2017-11-12 13:48:55 +02:00
|
|
|
/* Bluetooth Mesh */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <zephyr/types.h>
|
2019-06-26 10:33:55 -04:00
|
|
|
#include <sys/util.h>
|
2019-06-26 10:33:41 -04:00
|
|
|
#include <sys/byteorder.h>
|
2017-11-12 13:48:55 +02:00
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/conn.h>
|
|
|
|
#include <bluetooth/mesh.h>
|
|
|
|
|
|
|
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
2018-07-17 10:35:52 +03:00
|
|
|
#define LOG_MODULE_NAME bt_mesh_cfg_cli
|
2017-11-12 13:48:55 +02:00
|
|
|
#include "common/log.h"
|
|
|
|
|
2018-05-07 09:48:36 +03:00
|
|
|
#include "net.h"
|
2017-11-12 17:47:00 +02:00
|
|
|
#include "foundation.h"
|
|
|
|
|
2017-11-16 10:28:33 +02:00
|
|
|
#define CID_NVAL 0xffff
|
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
struct comp_data {
|
|
|
|
u8_t *status;
|
|
|
|
struct net_buf_simple *comp;
|
|
|
|
};
|
|
|
|
|
2017-11-14 20:45:26 +02:00
|
|
|
static s32_t msg_timeout = K_SECONDS(2);
|
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
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);
|
2019-02-11 17:14:19 +00:00
|
|
|
to_copy = MIN(net_buf_simple_tailroom(param->comp), buf->len);
|
2017-11-12 17:47:00 +02:00
|
|
|
net_buf_simple_add_mem(param->comp, buf->data, to_copy);
|
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
static void state_status_u8(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf,
|
|
|
|
u32_t expect_status)
|
|
|
|
{
|
|
|
|
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 != expect_status) {
|
|
|
|
BT_WARN("Unexpected Status (0x%08x != 0x%08x)",
|
|
|
|
cli->op_pending, expect_status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = cli->op_param;
|
|
|
|
*status = net_buf_simple_pull_u8(buf);
|
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 18:33:47 +02:00
|
|
|
static void beacon_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
2017-11-12 21:10:05 +02:00
|
|
|
state_status_u8(model, ctx, buf, OP_BEACON_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ttl_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
state_status_u8(model, ctx, buf, OP_DEFAULT_TTL_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void friend_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
state_status_u8(model, ctx, buf, OP_FRIEND_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gatt_proxy_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
state_status_u8(model, ctx, buf, OP_GATT_PROXY_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct relay_param {
|
2017-11-12 18:33:47 +02:00
|
|
|
u8_t *status;
|
2017-11-12 21:10:05 +02:00
|
|
|
u8_t *transmit;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void relay_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct relay_param *param;
|
2017-11-12 18:33:47 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
if (cli->op_pending != OP_RELAY_STATUS) {
|
|
|
|
BT_WARN("Unexpected Relay Status message");
|
2017-11-12 18:33:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
param = cli->op_param;
|
|
|
|
*param->status = net_buf_simple_pull_u8(buf);
|
|
|
|
*param->transmit = net_buf_simple_pull_u8(buf);
|
2017-11-12 18:33:47 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-12-01 10:54:38 +02:00
|
|
|
struct net_key_param {
|
|
|
|
u8_t *status;
|
|
|
|
u16_t net_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void net_key_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct net_key_param *param;
|
|
|
|
u16_t net_idx, app_idx;
|
|
|
|
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_NET_KEY_STATUS) {
|
|
|
|
BT_WARN("Unexpected Net Key Status message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
key_idx_unpack(buf, &net_idx, &app_idx);
|
|
|
|
|
|
|
|
param = cli->op_param;
|
|
|
|
if (param->net_idx != net_idx) {
|
|
|
|
BT_WARN("Net Key Status key index does not match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:38:43 +03:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-12-01 10:54:38 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:04:36 +02:00
|
|
|
struct app_key_param {
|
|
|
|
u8_t *status;
|
|
|
|
u16_t net_idx;
|
|
|
|
u16_t app_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void app_key_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct app_key_param *param;
|
|
|
|
u16_t net_idx, app_idx;
|
|
|
|
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_APP_KEY_STATUS) {
|
2017-12-01 10:54:26 +02:00
|
|
|
BT_WARN("Unexpected App Key Status message");
|
2017-11-12 23:04:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
key_idx_unpack(buf, &net_idx, &app_idx);
|
|
|
|
|
|
|
|
param = cli->op_param;
|
|
|
|
if (param->net_idx != net_idx || param->app_idx != app_idx) {
|
|
|
|
BT_WARN("App Key Status key indices did not match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:38:43 +03:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-12 23:04:36 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:38:44 +02:00
|
|
|
struct mod_app_param {
|
|
|
|
u8_t *status;
|
|
|
|
u16_t elem_addr;
|
|
|
|
u16_t mod_app_idx;
|
|
|
|
u16_t mod_id;
|
|
|
|
u16_t cid;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mod_app_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
u16_t elem_addr, mod_app_idx, mod_id, cid;
|
|
|
|
struct mod_app_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_MOD_APP_STATUS) {
|
|
|
|
BT_WARN("Unexpected Model App Status message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
elem_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
mod_app_idx = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
if (buf->len >= 4U) {
|
2017-11-12 23:38:44 +02:00
|
|
|
cid = net_buf_simple_pull_le16(buf);
|
|
|
|
} else {
|
2017-11-16 10:28:33 +02:00
|
|
|
cid = CID_NVAL;
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mod_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
|
|
|
param = cli->op_param;
|
|
|
|
if (param->elem_addr != elem_addr ||
|
2017-11-16 10:28:33 +02:00
|
|
|
param->mod_app_idx != mod_app_idx || param->mod_id != mod_id ||
|
|
|
|
param->cid != cid) {
|
2017-11-12 23:38:44 +02:00
|
|
|
BT_WARN("Model App Status parameters did not match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:38:43 +03:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-12 23:38:44 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:29:31 +02:00
|
|
|
struct mod_pub_param {
|
|
|
|
u16_t mod_id;
|
|
|
|
u16_t cid;
|
|
|
|
u16_t elem_addr;
|
|
|
|
u8_t *status;
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mod_pub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
u16_t mod_id, cid, elem_addr;
|
|
|
|
struct mod_pub_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_MOD_PUB_STATUS) {
|
|
|
|
BT_WARN("Unexpected Model Pub Status message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = cli->op_param;
|
|
|
|
if (param->cid != CID_NVAL) {
|
|
|
|
if (buf->len < 14) {
|
|
|
|
BT_WARN("Unexpected Mod Pub Status with SIG Model");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cid = sys_get_le16(&buf->data[10]);
|
|
|
|
mod_id = sys_get_le16(&buf->data[12]);
|
|
|
|
} else {
|
|
|
|
if (buf->len > 12) {
|
|
|
|
BT_WARN("Unexpected Mod Pub Status with Vendor Model");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cid = CID_NVAL;
|
|
|
|
mod_id = sys_get_le16(&buf->data[10]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mod_id != param->mod_id || cid != param->cid) {
|
|
|
|
BT_WARN("Mod Pub Model ID or Company ID mismatch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
|
|
|
|
elem_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
if (elem_addr != param->elem_addr) {
|
|
|
|
BT_WARN("Model Pub Status for unexpected element (0x%04x)",
|
|
|
|
elem_addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:58:06 +02:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
|
|
|
|
if (param->pub) {
|
|
|
|
param->pub->addr = net_buf_simple_pull_le16(buf);
|
|
|
|
param->pub->app_idx = net_buf_simple_pull_le16(buf);
|
|
|
|
param->pub->cred_flag = (param->pub->app_idx & BIT(12));
|
|
|
|
param->pub->app_idx &= BIT_MASK(12);
|
|
|
|
param->pub->ttl = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->period = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->transmit = net_buf_simple_pull_u8(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:51:28 +02:00
|
|
|
struct mod_sub_param {
|
|
|
|
u8_t *status;
|
|
|
|
u16_t elem_addr;
|
2017-11-24 13:36:05 +02:00
|
|
|
u16_t *sub_addr;
|
|
|
|
u16_t *expect_sub;
|
2017-11-12 23:51:28 +02:00
|
|
|
u16_t mod_id;
|
|
|
|
u16_t cid;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mod_sub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
u16_t elem_addr, sub_addr, mod_id, cid;
|
|
|
|
struct mod_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_MOD_SUB_STATUS) {
|
|
|
|
BT_WARN("Unexpected Model Subscription Status message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
elem_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
sub_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
if (buf->len >= 4U) {
|
2017-11-12 23:51:28 +02:00
|
|
|
cid = net_buf_simple_pull_le16(buf);
|
|
|
|
} else {
|
2017-11-16 10:28:33 +02:00
|
|
|
cid = CID_NVAL;
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mod_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
|
|
|
param = cli->op_param;
|
2017-11-24 13:36:05 +02:00
|
|
|
if (param->elem_addr != elem_addr || param->mod_id != mod_id ||
|
|
|
|
(param->expect_sub && *param->expect_sub != sub_addr) ||
|
2017-11-16 10:28:33 +02:00
|
|
|
param->cid != cid) {
|
2017-11-12 23:51:28 +02:00
|
|
|
BT_WARN("Model Subscription Status parameters did not match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 13:36:05 +02:00
|
|
|
if (param->sub_addr) {
|
|
|
|
*param->sub_addr = sub_addr;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:58:06 +02:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-12 23:51:28 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:22:09 +02:00
|
|
|
struct hb_sub_param {
|
|
|
|
u8_t *status;
|
2017-11-16 14:21:23 +02:00
|
|
|
struct bt_mesh_cfg_hb_sub *sub;
|
2017-11-13 00:22:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void hb_sub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct hb_sub_param *param;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = cli->op_param;
|
|
|
|
|
2017-11-14 20:42:48 +02:00
|
|
|
*param->status = net_buf_simple_pull_u8(buf);
|
2017-11-13 00:22:09 +02:00
|
|
|
|
2017-11-16 14:21:23 +02:00
|
|
|
param->sub->src = net_buf_simple_pull_le16(buf);
|
|
|
|
param->sub->dst = net_buf_simple_pull_le16(buf);
|
|
|
|
param->sub->period = net_buf_simple_pull_u8(buf);
|
|
|
|
param->sub->count = net_buf_simple_pull_u8(buf);
|
|
|
|
param->sub->min = net_buf_simple_pull_u8(buf);
|
|
|
|
param->sub->max = net_buf_simple_pull_u8(buf);
|
2017-11-13 00:22:09 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-14 10:46:22 +02:00
|
|
|
struct hb_pub_param {
|
2017-11-16 12:50:13 +02:00
|
|
|
u8_t *status;
|
|
|
|
struct bt_mesh_cfg_hb_pub *pub;
|
2017-11-14 10:46:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void hb_pub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct hb_pub_param *param;
|
|
|
|
|
|
|
|
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_PUB_STATUS) {
|
|
|
|
BT_WARN("Unexpected Heartbeat Publication Status message");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:50:13 +02:00
|
|
|
param = cli->op_param;
|
|
|
|
|
2017-11-14 10:46:22 +02:00
|
|
|
*param->status = net_buf_simple_pull_u8(buf);
|
2017-11-16 12:50:13 +02:00
|
|
|
|
|
|
|
if (param->pub) {
|
|
|
|
param->pub->dst = net_buf_simple_pull_le16(buf);
|
|
|
|
param->pub->count = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->period = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->ttl = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->feat = net_buf_simple_pull_u8(buf);
|
|
|
|
param->pub->net_idx = net_buf_simple_pull_u8(buf);
|
|
|
|
}
|
2017-11-14 10:46:22 +02:00
|
|
|
|
|
|
|
k_sem_give(&cli->op_sync);
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:48:55 +02:00
|
|
|
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
2017-11-12 17:47:00 +02:00
|
|
|
{ OP_DEV_COMP_DATA_STATUS, 15, comp_data_status },
|
2017-11-12 18:33:47 +02:00
|
|
|
{ OP_BEACON_STATUS, 1, beacon_status },
|
2017-11-12 21:10:05 +02:00
|
|
|
{ OP_DEFAULT_TTL_STATUS, 1, ttl_status },
|
|
|
|
{ OP_FRIEND_STATUS, 1, friend_status },
|
|
|
|
{ OP_GATT_PROXY_STATUS, 1, gatt_proxy_status },
|
|
|
|
{ OP_RELAY_STATUS, 2, relay_status },
|
2017-12-01 10:54:38 +02:00
|
|
|
{ OP_NET_KEY_STATUS, 3, net_key_status },
|
2017-11-12 23:04:36 +02:00
|
|
|
{ OP_APP_KEY_STATUS, 4, app_key_status },
|
2017-11-12 23:38:44 +02:00
|
|
|
{ OP_MOD_APP_STATUS, 7, mod_app_status },
|
2017-11-16 12:29:31 +02:00
|
|
|
{ OP_MOD_PUB_STATUS, 12, mod_pub_status },
|
2017-11-12 23:51:28 +02:00
|
|
|
{ OP_MOD_SUB_STATUS, 7, mod_sub_status },
|
2017-11-13 00:22:09 +02:00
|
|
|
{ OP_HEARTBEAT_SUB_STATUS, 9, hb_sub_status },
|
2017-11-14 10:46:22 +02:00
|
|
|
{ OP_HEARTBEAT_PUB_STATUS, 10, hb_pub_status },
|
2017-11-12 13:48:55 +02:00
|
|
|
BT_MESH_MODEL_OP_END,
|
|
|
|
};
|
2017-11-12 17:47:00 +02:00
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
static int cli_prepare(void *param, u32_t op)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
|
|
|
if (!cli) {
|
|
|
|
BT_ERR("No available Configuration Client context!");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cli->op_pending) {
|
|
|
|
BT_WARN("Another synchronous operation pending");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
cli->op_param = param;
|
|
|
|
cli->op_pending = op;
|
|
|
|
|
2017-11-12 18:33:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
static void cli_reset(void)
|
2017-11-22 18:51:45 +02:00
|
|
|
{
|
2019-03-26 19:57:45 -06:00
|
|
|
cli->op_pending = 0U;
|
2018-03-19 16:45:09 +02:00
|
|
|
cli->op_param = NULL;
|
|
|
|
}
|
2017-11-22 18:51:45 +02:00
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
static int cli_wait(void)
|
|
|
|
{
|
|
|
|
int err;
|
2017-11-22 18:51:45 +02:00
|
|
|
|
|
|
|
err = k_sem_take(&cli->op_sync, msg_timeout);
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-22 18:51:45 +02:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
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)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
2017-11-12 17:47:00 +02:00
|
|
|
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;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_DEV_COMP_DATA_STATUS);
|
2017-11-12 18:33:47 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
2017-11-12 17:47:00 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_DEV_COMP_DATA_GET);
|
|
|
|
net_buf_simple_add_u8(&msg, page);
|
2017-11-12 17:47:00 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 17:47:00 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 17:47:00 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 17:47:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
static int get_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
|
|
|
u8_t *val)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 0 + 4);
|
2017-11-12 18:33:47 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(val, rsp);
|
2017-11-12 18:33:47 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, op);
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 18:33:47 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 18:33:47 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
static int set_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
|
|
|
u8_t new_val, u8_t *val)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 1 + 4);
|
2017-11-12 18:33:47 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(val, rsp);
|
2017-11-12 18:33:47 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, op);
|
|
|
|
net_buf_simple_add_u8(&msg, new_val);
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 18:33:47 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 18:33:47 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
int bt_mesh_cfg_beacon_get(u16_t net_idx, u16_t addr, u8_t *status)
|
|
|
|
{
|
|
|
|
return get_state_u8(net_idx, addr, OP_BEACON_GET, OP_BEACON_STATUS,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_beacon_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status)
|
|
|
|
{
|
|
|
|
return set_state_u8(net_idx, addr, OP_BEACON_SET, OP_BEACON_STATUS,
|
|
|
|
val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_ttl_get(u16_t net_idx, u16_t addr, u8_t *ttl)
|
|
|
|
{
|
|
|
|
return get_state_u8(net_idx, addr, OP_DEFAULT_TTL_GET,
|
|
|
|
OP_DEFAULT_TTL_STATUS, ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_ttl_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *ttl)
|
|
|
|
{
|
|
|
|
return set_state_u8(net_idx, addr, OP_DEFAULT_TTL_SET,
|
|
|
|
OP_DEFAULT_TTL_STATUS, val, ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_friend_get(u16_t net_idx, u16_t addr, u8_t *status)
|
|
|
|
{
|
|
|
|
return get_state_u8(net_idx, addr, OP_FRIEND_GET,
|
|
|
|
OP_FRIEND_STATUS, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_friend_set(u16_t net_idx, u16_t addr, u8_t val, u8_t *status)
|
|
|
|
{
|
|
|
|
return set_state_u8(net_idx, addr, OP_FRIEND_SET, OP_FRIEND_STATUS,
|
|
|
|
val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_gatt_proxy_get(u16_t net_idx, u16_t addr, u8_t *status)
|
|
|
|
{
|
|
|
|
return get_state_u8(net_idx, addr, OP_GATT_PROXY_GET,
|
|
|
|
OP_GATT_PROXY_STATUS, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_gatt_proxy_set(u16_t net_idx, u16_t addr, u8_t val,
|
|
|
|
u8_t *status)
|
|
|
|
{
|
|
|
|
return set_state_u8(net_idx, addr, OP_GATT_PROXY_SET,
|
|
|
|
OP_GATT_PROXY_STATUS, val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_relay_get(u16_t net_idx, u16_t addr, u8_t *status,
|
|
|
|
u8_t *transmit)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 0 + 4);
|
2017-11-12 21:10:05 +02:00
|
|
|
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 relay_param param = {
|
|
|
|
.status = status,
|
|
|
|
.transmit = transmit,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_RELAY_STATUS);
|
2017-11-12 21:10:05 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_RELAY_GET);
|
2017-11-12 21:10:05 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 21:10:05 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 21:10:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
|
|
|
|
u8_t new_transmit, u8_t *status, u8_t *transmit)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 2 + 4);
|
2017-11-12 21:10:05 +02:00
|
|
|
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 relay_param param = {
|
|
|
|
.status = status,
|
|
|
|
.transmit = transmit,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_RELAY_STATUS);
|
2017-11-12 21:10:05 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_RELAY_SET);
|
|
|
|
net_buf_simple_add_u8(&msg, new_relay);
|
|
|
|
net_buf_simple_add_u8(&msg, new_transmit);
|
2017-11-12 21:10:05 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 21:10:05 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 21:10:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2017-12-01 10:54:38 +02:00
|
|
|
int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
|
|
|
const u8_t net_key[16], u8_t *status)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 18 + 4);
|
2017-12-01 10:54:38 +02:00
|
|
|
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 net_key_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_NET_KEY_STATUS);
|
2017-12-01 10:54:38 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_NET_KEY_ADD);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
net_buf_simple_add_mem(&msg, net_key, 16);
|
2017-12-01 10:54:38 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-12-01 10:54:38 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-12-01 10:54:38 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-12-01 10:54:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-12-01 10:54:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:04:36 +02:00
|
|
|
int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
|
|
|
u16_t key_app_idx, const u8_t app_key[16],
|
|
|
|
u8_t *status)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 1 + 19 + 4);
|
2017-11-12 23:04:36 +02:00
|
|
|
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 app_key_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
.app_idx = key_app_idx,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_APP_KEY_STATUS);
|
2017-11-12 23:04:36 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_APP_KEY_ADD);
|
|
|
|
key_idx_pack(&msg, key_net_idx, key_app_idx);
|
|
|
|
net_buf_simple_add_mem(&msg, app_key, 16);
|
2017-11-12 23:04:36 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 23:04:36 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:04:36 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:38:44 +02:00
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:38:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 23:04:36 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 10:28:33 +02:00
|
|
|
static int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_app_idx, u16_t mod_id, u16_t cid,
|
|
|
|
u8_t *status)
|
2017-11-12 23:38:44 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 8 + 4);
|
2017-11-12 23:38:44 +02:00
|
|
|
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 mod_app_param param = {
|
|
|
|
.status = status,
|
|
|
|
.elem_addr = elem_addr,
|
|
|
|
.mod_app_idx = mod_app_idx,
|
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_MOD_APP_STATUS);
|
2017-11-12 23:38:44 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_MOD_APP_BIND);
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_le16(&msg, mod_app_idx);
|
2017-11-12 23:38:44 +02:00
|
|
|
|
2017-11-16 10:28:33 +02:00
|
|
|
if (cid != CID_NVAL) {
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
2017-11-12 23:38:44 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 23:38:44 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:38:44 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:38:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_app_idx, u16_t mod_id, u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_app_bind(net_idx, addr, elem_addr, mod_app_idx, mod_id,
|
2017-11-16 10:28:33 +02:00
|
|
|
CID_NVAL, status);
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_app_idx, u16_t mod_id, u16_t cid,
|
|
|
|
u8_t *status)
|
|
|
|
{
|
2017-11-16 10:28:33 +02:00
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_app_bind(net_idx, addr, elem_addr, mod_app_idx, mod_id, cid,
|
|
|
|
status);
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2017-11-18 11:52:21 +02:00
|
|
|
static int mod_sub(u32_t op, 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)
|
2017-11-12 23:51:28 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 8 + 4);
|
2017-11-12 23:51:28 +02:00
|
|
|
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 mod_sub_param param = {
|
|
|
|
.status = status,
|
|
|
|
.elem_addr = elem_addr,
|
2017-11-24 13:36:05 +02:00
|
|
|
.expect_sub = &sub_addr,
|
2017-11-12 23:51:28 +02:00
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_MOD_SUB_STATUS);
|
2017-11-12 23:51:28 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, op);
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_le16(&msg, sub_addr);
|
2017-11-12 23:51:28 +02:00
|
|
|
|
2017-11-16 10:28:33 +02:00
|
|
|
if (cid != CID_NVAL) {
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
2017-11-12 23:51:28 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-12 23:51:28 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:51:28 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-12 23:51:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_add(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t sub_addr, u16_t mod_id, u8_t *status)
|
|
|
|
{
|
2017-11-18 11:52:21 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_ADD, net_idx, addr, elem_addr, sub_addr,
|
|
|
|
mod_id, CID_NVAL, status);
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-11-16 10:28:33 +02:00
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-18 11:52:21 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_ADD, net_idx, addr, elem_addr, sub_addr,
|
|
|
|
mod_id, cid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t sub_addr, u16_t mod_id, u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_sub(OP_MOD_SUB_DEL, net_idx, addr, elem_addr, sub_addr,
|
|
|
|
mod_id, CID_NVAL, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del_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)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_sub(OP_MOD_SUB_DEL, net_idx, addr, elem_addr, sub_addr,
|
|
|
|
mod_id, cid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_overwrite(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t sub_addr, u16_t mod_id, u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_sub(OP_MOD_SUB_OVERWRITE, net_idx, addr, elem_addr,
|
|
|
|
sub_addr, mod_id, CID_NVAL, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_overwrite_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)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_sub(OP_MOD_SUB_OVERWRITE, net_idx, addr, elem_addr,
|
|
|
|
sub_addr, mod_id, cid, status);
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 13:36:05 +02:00
|
|
|
static int mod_sub_va(u32_t op, u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
const u8_t label[16], u16_t mod_id, u16_t cid,
|
|
|
|
u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 22 + 4);
|
2017-11-24 13:36:05 +02:00
|
|
|
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 mod_sub_param param = {
|
|
|
|
.status = status,
|
|
|
|
.elem_addr = elem_addr,
|
|
|
|
.sub_addr = virt_addr,
|
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_MOD_SUB_STATUS);
|
2017-11-24 13:36:05 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x label %s",
|
|
|
|
net_idx, addr, elem_addr, label);
|
|
|
|
BT_DBG("mod_id 0x%04x cid 0x%04x", mod_id, cid);
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, op);
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_mem(&msg, label, 16);
|
2017-11-24 13:36:05 +02:00
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
2017-11-24 13:36:05 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-24 13:36:05 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-24 13:36:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-24 13:36:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_add(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
const u8_t label[16], u16_t mod_id,
|
|
|
|
u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_ADD, net_idx, addr, elem_addr, label,
|
|
|
|
mod_id, CID_NVAL, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_add_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
const u8_t label[16], u16_t mod_id,
|
|
|
|
u16_t cid, u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_ADD, net_idx, addr, elem_addr, label,
|
|
|
|
mod_id, cid, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_del(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
const u8_t label[16], u16_t mod_id,
|
|
|
|
u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_DEL, net_idx, addr, elem_addr, label,
|
|
|
|
mod_id, CID_NVAL, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_del_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
const u8_t label[16], u16_t mod_id,
|
|
|
|
u16_t cid, u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_DEL, net_idx, addr, elem_addr, label,
|
|
|
|
mod_id, cid, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_overwrite(u16_t net_idx, u16_t addr,
|
|
|
|
u16_t elem_addr, const u8_t label[16],
|
|
|
|
u16_t mod_id, u16_t *virt_addr,
|
|
|
|
u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, net_idx, addr, elem_addr,
|
|
|
|
label, mod_id, CID_NVAL, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_overwrite_vnd(u16_t net_idx, u16_t addr,
|
|
|
|
u16_t elem_addr, const u8_t label[16],
|
|
|
|
u16_t mod_id, u16_t cid,
|
|
|
|
u16_t *virt_addr, u8_t *status)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, net_idx, addr, elem_addr,
|
|
|
|
label, mod_id, cid, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:29:31 +02:00
|
|
|
static int mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, u16_t cid,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, u8_t *status)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 6 + 4);
|
2017-11-16 12:29:31 +02:00
|
|
|
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 mod_pub_param param = {
|
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
.elem_addr = elem_addr,
|
|
|
|
.status = status,
|
|
|
|
.pub = pub,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_MOD_PUB_STATUS);
|
2017-11-16 12:29:31 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_MOD_PUB_GET);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-16 12:29:31 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-16 12:29:31 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-16 12:29:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub,
|
|
|
|
u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_pub_get(net_idx, addr, elem_addr, mod_id, CID_NVAL,
|
|
|
|
pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, u16_t cid,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, u8_t *status)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-01-31 13:06:21 -08:00
|
|
|
return mod_pub_get(net_idx, addr, elem_addr, mod_id, cid, pub, status);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, u16_t cid,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, u8_t *status)
|
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 13 + 4);
|
2017-11-16 12:29:31 +02:00
|
|
|
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 mod_pub_param param = {
|
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
.elem_addr = elem_addr,
|
|
|
|
.status = status,
|
|
|
|
.pub = pub,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_MOD_PUB_STATUS);
|
2017-11-16 12:29:31 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_MOD_PUB_SET);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_le16(&msg, pub->addr);
|
|
|
|
net_buf_simple_add_le16(&msg, (pub->app_idx & (pub->cred_flag << 12)));
|
|
|
|
net_buf_simple_add_u8(&msg, pub->ttl);
|
|
|
|
net_buf_simple_add_u8(&msg, pub->period);
|
|
|
|
net_buf_simple_add_u8(&msg, pub->transmit);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-16 12:29:31 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-16 12:29:31 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-16 12:29:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, struct bt_mesh_cfg_mod_pub *pub,
|
|
|
|
u8_t *status)
|
|
|
|
{
|
|
|
|
return mod_pub_set(net_idx, addr, elem_addr, mod_id, CID_NVAL,
|
|
|
|
pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_set_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|
|
|
u16_t mod_id, u16_t cid,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, u8_t *status)
|
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-01-31 13:06:21 -08:00
|
|
|
return mod_pub_set(net_idx, addr, elem_addr, mod_id, cid, pub, status);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 14:21:23 +02:00
|
|
|
int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr,
|
|
|
|
struct bt_mesh_cfg_hb_sub *sub, u8_t *status)
|
2017-11-13 00:22:09 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 5 + 4);
|
2017-11-13 00:22:09 +02:00
|
|
|
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,
|
2017-11-16 14:21:23 +02:00
|
|
|
.sub = sub,
|
2017-11-13 00:22:09 +02:00
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS);
|
2017-11-13 00:22:09 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_SUB_SET);
|
|
|
|
net_buf_simple_add_le16(&msg, sub->src);
|
|
|
|
net_buf_simple_add_le16(&msg, sub->dst);
|
|
|
|
net_buf_simple_add_u8(&msg, sub->period);
|
2017-11-14 20:42:48 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-14 20:42:48 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 20:42:48 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 20:42:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-14 20:42:48 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 14:21:23 +02:00
|
|
|
int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr,
|
|
|
|
struct bt_mesh_cfg_hb_sub *sub, u8_t *status)
|
2017-11-14 20:42:48 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 0 + 4);
|
2017-11-14 20:42:48 +02:00
|
|
|
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,
|
2017-11-16 14:21:23 +02:00
|
|
|
.sub = sub,
|
2017-11-14 20:42:48 +02:00
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS);
|
2017-11-14 20:42:48 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_SUB_GET);
|
2017-11-13 00:22:09 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-13 00:22:09 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-13 00:22:09 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-13 00:22:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-13 00:22:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 12:50:13 +02:00
|
|
|
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
|
|
|
const struct bt_mesh_cfg_hb_pub *pub, u8_t *status)
|
2017-11-14 10:46:22 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 9 + 4);
|
2017-11-14 10:46:22 +02:00
|
|
|
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_pub_param param = {
|
|
|
|
.status = status,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS);
|
2017-11-14 10:46:22 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_PUB_SET);
|
|
|
|
net_buf_simple_add_le16(&msg, pub->dst);
|
|
|
|
net_buf_simple_add_u8(&msg, pub->count);
|
|
|
|
net_buf_simple_add_u8(&msg, pub->period);
|
|
|
|
net_buf_simple_add_u8(&msg, pub->ttl);
|
|
|
|
net_buf_simple_add_le16(&msg, pub->feat);
|
|
|
|
net_buf_simple_add_le16(&msg, pub->net_idx);
|
2017-11-14 10:46:22 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-14 10:46:22 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 10:46:22 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 10:46:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-14 10:46:22 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 12:50:13 +02:00
|
|
|
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
|
|
|
struct bt_mesh_cfg_hb_pub *pub, u8_t *status)
|
2017-11-14 20:18:04 +02:00
|
|
|
{
|
2018-02-10 10:32:58 +02:00
|
|
|
NET_BUF_SIMPLE_DEFINE(msg, 2 + 0 + 4);
|
2017-11-14 20:18:04 +02:00
|
|
|
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_pub_param param = {
|
|
|
|
.status = status,
|
2017-11-16 12:50:13 +02:00
|
|
|
.pub = pub,
|
2017-11-14 20:18:04 +02:00
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS);
|
2017-11-14 20:18:04 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_PUB_GET);
|
2017-11-14 20:18:04 +02:00
|
|
|
|
2018-02-10 10:32:58 +02:00
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
2017-11-14 20:18:04 +02:00
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 20:18:04 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2018-03-19 16:45:09 +02:00
|
|
|
cli_reset();
|
2017-11-14 20:18:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:45:09 +02:00
|
|
|
return cli_wait();
|
2017-11-14 20:18:04 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 20:45:26 +02:00
|
|
|
s32_t bt_mesh_cfg_cli_timeout_get(void)
|
|
|
|
{
|
|
|
|
return msg_timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_mesh_cfg_cli_timeout_set(s32_t timeout)
|
|
|
|
{
|
|
|
|
msg_timeout = timeout;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
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;
|
|
|
|
}
|