Bluetooth: Mesh: Add support for sending Heartbeat Subscription Set

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-13 00:22:09 +02:00 committed by Johan Hedberg
commit f50b99572f
2 changed files with 118 additions and 0 deletions

View file

@ -76,6 +76,9 @@ int bt_mesh_cfg_mod_sub_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t sub_addr, u16_t mod_id, u16_t cid,
u8_t *status);
int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr, u16_t src, u16_t dst,
u8_t period, u8_t *status);
/**
* @}
*/

View file

@ -280,6 +280,72 @@ static void mod_sub_status(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync);
}
struct hb_sub_param {
u8_t *status;
u16_t src;
u16_t dst;
u8_t *period;
u8_t *count;
u8_t *min;
u8_t *max;
};
static void hb_sub_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
u16_t src, dst;
struct hb_sub_param *param;
u8_t status;
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_HEARTBEAT_SUB_STATUS) {
BT_WARN("Unexpected Heartbeat Subscription Status message");
return;
}
status = net_buf_simple_pull_u8(buf);
src = net_buf_simple_pull_le16(buf);
dst = net_buf_simple_pull_le16(buf);
param = cli->op_param;
if (param->src != src || param->dst != dst) {
BT_WARN("Heartbeat Subscription Status parameters mismatch");
return;
}
*param->status = status;
if (param->period) {
*param->period = net_buf_simple_pull_u8(buf);
} else {
net_buf_simple_pull(buf, 1);
}
if (param->count) {
*param->count = net_buf_simple_pull_u8(buf);
} else {
net_buf_simple_pull(buf, 1);
}
if (param->min) {
*param->min = net_buf_simple_pull_u8(buf);
} else {
net_buf_simple_pull(buf, 1);
}
if (param->max) {
*param->max = net_buf_simple_pull_u8(buf);
} else {
net_buf_simple_pull(buf, 1);
}
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 },
{ OP_BEACON_STATUS, 1, beacon_status },
@ -290,6 +356,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
{ OP_APP_KEY_STATUS, 4, app_key_status },
{ OP_MOD_APP_STATUS, 7, mod_app_status },
{ OP_MOD_SUB_STATUS, 7, mod_sub_status },
{ OP_HEARTBEAT_SUB_STATUS, 9, hb_sub_status },
BT_MESH_MODEL_OP_END,
};
@ -743,6 +810,54 @@ int bt_mesh_cfg_mod_sub_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
true, cid, status);
}
int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr, u16_t src, u16_t dst,
u8_t period, u8_t *status)
{
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 5 + 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 hb_sub_param param = {
.status = status,
.src = src,
.dst = dst,
};
int err;
err = check_cli();
if (err) {
return err;
}
bt_mesh_model_msg_init(msg, OP_HEARTBEAT_SUB_SET);
net_buf_simple_add_le16(msg, src);
net_buf_simple_add_le16(msg, dst);
net_buf_simple_add_u8(msg, period);
err = bt_mesh_model_send(cli->model, &ctx, msg, NULL, NULL);
if (err) {
BT_ERR("model_send() failed (err %d)", err);
return err;
}
if (!status) {
return 0;
}
cli->op_param = &param;
cli->op_pending = OP_HEARTBEAT_SUB_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);