2017-11-12 13:48:55 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/zephyr.h>
|
2017-11-12 13:48:55 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <zephyr/types.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/sys/util.h>
|
|
|
|
#include <zephyr/sys/byteorder.h>
|
|
|
|
#include <zephyr/sys/check.h>
|
2017-11-12 13:48:55 +02:00
|
|
|
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/conn.h>
|
|
|
|
#include <zephyr/bluetooth/mesh.h>
|
2017-11-12 13:48:55 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2019-10-08 09:39:48 +02:00
|
|
|
/* 2 byte dummy opcode for getting compile time buffer sizes. */
|
|
|
|
#define DUMMY_2_BYTE_OP BT_MESH_MODEL_OP_2(0xff, 0xff)
|
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
struct comp_data {
|
2021-03-23 14:35:03 +01:00
|
|
|
uint8_t *page;
|
2017-11-12 17:47:00 +02:00
|
|
|
struct net_buf_simple *comp;
|
|
|
|
};
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int32_t msg_timeout;
|
2017-11-14 20:45:26 +02:00
|
|
|
|
2017-11-12 17:47:00 +02:00
|
|
|
static struct bt_mesh_cfg_cli *cli;
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int comp_data_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-12 17:47:00 +02:00
|
|
|
{
|
|
|
|
struct comp_data *param;
|
2021-12-07 12:41:05 +01:00
|
|
|
uint8_t page;
|
2017-11-12 17:47:00 +02:00
|
|
|
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));
|
|
|
|
|
2021-12-07 12:41:05 +01:00
|
|
|
page = net_buf_simple_pull_u8(buf);
|
2021-03-23 14:35:03 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_DEV_COMP_DATA_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
|
|
|
if (param->page) {
|
2021-12-07 12:41:05 +01:00
|
|
|
*(param->page) = page;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2017-11-12 17:47:00 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (param->comp) {
|
|
|
|
to_copy = MIN(net_buf_simple_tailroom(param->comp), buf->len);
|
|
|
|
net_buf_simple_add_mem(param->comp, buf->data, to_copy);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2017-11-12 17:47:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-30 19:28:39 +08:00
|
|
|
static uint8_t state_status_u8(struct bt_mesh_model *model,
|
2021-04-14 13:17:59 +02:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf,
|
|
|
|
uint32_t expect_status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2021-11-29 16:17:52 +01:00
|
|
|
uint8_t *param;
|
|
|
|
uint8_t status;
|
2017-11-12 21:10:05 +02:00
|
|
|
|
|
|
|
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
2022-06-30 19:28:39 +08:00
|
|
|
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
|
|
|
bt_hex(buf->data, buf->len));
|
2017-11-12 21:10:05 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
2017-11-12 21:10:05 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, expect_status, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2017-11-12 21:10:05 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param) {
|
|
|
|
*param = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-06-30 19:28:39 +08:00
|
|
|
|
|
|
|
return status;
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int beacon_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
2022-06-30 19:28:39 +08:00
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
status = state_status_u8(model, ctx, buf, OP_BEACON_STATUS);
|
|
|
|
|
|
|
|
if (cli->cb && cli->cb->beacon_status) {
|
|
|
|
cli->cb->beacon_status(cli, ctx->addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int ttl_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
|
|
|
{
|
2022-06-30 19:28:39 +08:00
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
status = state_status_u8(model, ctx, buf, OP_DEFAULT_TTL_STATUS);
|
|
|
|
|
|
|
|
if (cli->cb && cli->cb->ttl_status) {
|
|
|
|
cli->cb->ttl_status(cli, ctx->addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int friend_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
|
|
|
{
|
2022-06-30 19:28:39 +08:00
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
status = state_status_u8(model, ctx, buf, OP_FRIEND_STATUS);
|
|
|
|
|
|
|
|
if (cli->cb && cli->cb->friend_status) {
|
|
|
|
cli->cb->friend_status(cli, ctx->addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int gatt_proxy_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
|
|
|
{
|
2022-06-30 19:28:39 +08:00
|
|
|
|
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
status = state_status_u8(model, ctx, buf, OP_GATT_PROXY_STATUS);
|
|
|
|
|
|
|
|
if (cli->cb && cli->cb->gatt_proxy_status) {
|
|
|
|
cli->cb->gatt_proxy_status(cli, ctx->addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
struct krp_param {
|
|
|
|
uint8_t *status;
|
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t *phase;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int krp_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct krp_param *param;
|
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t status, phase;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
net_idx = net_buf_simple_pull_le16(buf) & 0xfff;
|
|
|
|
phase = net_buf_simple_pull_u8(buf);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_KRP_STATUS, ctx->addr, (void **)¶m)) {
|
|
|
|
if (param->net_idx != net_idx) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->phase) {
|
|
|
|
*param->phase = phase;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:10:05 +02:00
|
|
|
struct relay_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint8_t *transmit;
|
2017-11-12 21:10:05 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int relay_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
|
|
|
{
|
|
|
|
struct relay_param *param;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint8_t status;
|
|
|
|
uint8_t transmit;
|
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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
transmit = net_buf_simple_pull_u8(buf);
|
|
|
|
|
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_RELAY_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2021-12-08 20:00:19 +08:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2021-12-08 20:00:19 +08:00
|
|
|
if (param->transmit) {
|
|
|
|
*param->transmit = transmit;
|
|
|
|
}
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2022-07-08 11:25:27 +08:00
|
|
|
if (cli->cb && cli->cb->relay_status) {
|
|
|
|
cli->cb->relay_status(cli, ctx->addr, status, transmit);
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2017-11-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int net_transmit_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2021-02-12 11:47:47 +01:00
|
|
|
{
|
2022-06-30 19:28:39 +08:00
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
status = state_status_u8(model, ctx, buf, OP_NET_TRANSMIT_STATUS);
|
|
|
|
|
|
|
|
if (cli->cb && cli->cb->network_transmit_status) {
|
|
|
|
cli->cb->network_transmit_status(cli, ctx->addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2021-02-12 11:47:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 10:54:38 +02:00
|
|
|
struct net_key_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint16_t net_idx;
|
2017-12-01 10:54:38 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int net_key_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-12-01 10:54:38 +02:00
|
|
|
{
|
|
|
|
struct net_key_param *param;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t status;
|
2022-07-08 11:25:27 +08:00
|
|
|
int err;
|
2017-12-01 10:54:38 +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));
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
2020-04-22 14:02:18 +02:00
|
|
|
net_idx = net_buf_simple_pull_le16(buf) & 0xfff;
|
2017-12-01 10:54:38 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2017-12-01 10:54:38 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->net_idx != net_idx) {
|
|
|
|
BT_WARN("Net Key Status key index does not match");
|
2022-07-08 11:25:27 +08:00
|
|
|
err = -ENOENT;
|
|
|
|
goto done;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2017-12-01 10:54:38 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-07-08 11:25:27 +08:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (cli->cb && cli->cb->net_key_status) {
|
|
|
|
cli->cb->net_key_status(cli, ctx->addr, status, net_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2017-12-01 10:54:38 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 10:14:12 +02:00
|
|
|
struct net_key_list_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t *keys;
|
2020-04-22 10:14:12 +02:00
|
|
|
size_t *key_cnt;
|
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int net_key_list(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
struct net_key_list_param *param;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NET_KEY_LIST, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (param->keys && param->key_cnt) {
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) {
|
|
|
|
key_idx_unpack(buf, ¶m->keys[i],
|
|
|
|
¶m->keys[i + 1]);
|
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (i < *param->key_cnt && buf->len >= 2) {
|
|
|
|
param->keys[i++] =
|
|
|
|
net_buf_simple_pull_le16(buf) & 0xfff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->len > 0) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
2021-04-27 15:59:54 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
*param->key_cnt = i;
|
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
|
|
|
return 0;
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int node_reset_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2020-09-23 09:47:29 +08:00
|
|
|
{
|
|
|
|
bool *param = NULL;
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x",
|
|
|
|
ctx->net_idx, ctx->app_idx, ctx->addr);
|
2020-09-23 09:47:29 +08:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NODE_RESET_STATUS,
|
|
|
|
ctx->addr, (void **)¶m)) {
|
|
|
|
|
|
|
|
if (param) {
|
|
|
|
*param = true;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-06-30 19:28:39 +08:00
|
|
|
|
|
|
|
if (cli->cb && cli->cb->node_reset_status) {
|
|
|
|
cli->cb->node_reset_status(cli, ctx->addr);
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2020-09-23 09:47:29 +08:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:04:36 +02:00
|
|
|
struct app_key_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint16_t net_idx;
|
|
|
|
uint16_t app_idx;
|
2017-11-12 23:04:36 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int app_key_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-12 23:04:36 +02:00
|
|
|
{
|
|
|
|
struct app_key_param *param;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t net_idx, app_idx;
|
|
|
|
uint8_t status;
|
2022-07-08 11:25:27 +08:00
|
|
|
int err;
|
2017-11-12 23:04:36 +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));
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
key_idx_unpack(buf, &net_idx, &app_idx);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2017-11-12 23:04:36 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->net_idx != net_idx || param->app_idx != app_idx) {
|
|
|
|
BT_WARN("App Key Status key indices did not match");
|
2022-07-08 11:25:27 +08:00
|
|
|
err = -ENOENT;
|
|
|
|
goto done;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2017-11-12 23:04:36 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-07-08 11:25:27 +08:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (cli->cb && cli->cb->app_key_status) {
|
|
|
|
cli->cb->app_key_status(cli, ctx->addr, status, net_idx,
|
|
|
|
app_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2017-11-12 23:04:36 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 10:14:12 +02:00
|
|
|
struct app_key_list_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t *status;
|
|
|
|
uint16_t *keys;
|
2020-04-22 10:14:12 +02:00
|
|
|
size_t *key_cnt;
|
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int app_key_list(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
struct app_key_list_param *param;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t status;
|
2020-04-22 10:14:12 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
net_idx = net_buf_simple_pull_le16(buf) & 0xfff;
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_APP_KEY_LIST, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->net_idx != net_idx) {
|
|
|
|
BT_WARN("App Key List Net Key index did not match");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (param->keys && param->key_cnt) {
|
2021-04-27 15:59:54 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) {
|
|
|
|
key_idx_unpack(buf, ¶m->keys[i],
|
|
|
|
¶m->keys[i + 1]);
|
|
|
|
}
|
|
|
|
|
2022-08-22 16:56:47 +02:00
|
|
|
if (i < *param->key_cnt && buf->len == 2) {
|
|
|
|
param->keys[i++] = net_buf_simple_pull_le16(buf) & 0xfff;
|
|
|
|
}
|
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (buf->len > 0U) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*param->key_cnt = i;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:38:44 +02:00
|
|
|
struct mod_app_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint16_t elem_addr;
|
|
|
|
uint16_t mod_app_idx;
|
|
|
|
uint16_t mod_id;
|
|
|
|
uint16_t cid;
|
2017-11-12 23:38:44 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_app_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-12 23:38:44 +02:00
|
|
|
{
|
|
|
|
struct mod_app_param *param;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint16_t elem_addr, mod_app_idx, mod_id, cid;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t status;
|
2022-07-08 11:25:27 +08:00
|
|
|
int err;
|
2017-11-12 23:38:44 +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));
|
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
if ((buf->len != 7U) && (buf->len != 9U)) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:38:44 +02:00
|
|
|
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);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_APP_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2017-11-12 23:38:44 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->elem_addr != elem_addr ||
|
|
|
|
param->mod_app_idx != mod_app_idx ||
|
|
|
|
param->mod_id != mod_id || param->cid != cid) {
|
|
|
|
BT_WARN("Model App Status parameters did not match");
|
2022-07-08 11:25:27 +08:00
|
|
|
err = -ENOENT;
|
|
|
|
goto done;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2017-11-12 23:38:44 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-07-08 11:25:27 +08:00
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (cli->cb && cli->cb->mod_app_status) {
|
|
|
|
cli->cb->mod_app_status(cli, ctx->addr, status, elem_addr,
|
|
|
|
mod_app_idx, (cid << 16) | mod_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 10:14:12 +02:00
|
|
|
struct mod_member_list_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint16_t elem_addr;
|
|
|
|
uint16_t mod_id;
|
|
|
|
uint16_t cid;
|
|
|
|
uint16_t *members;
|
2020-04-22 10:14:12 +02:00
|
|
|
size_t *member_cnt;
|
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_member_list_handle(struct bt_mesh_msg_ctx *ctx,
|
2021-11-29 16:17:52 +01:00
|
|
|
struct net_buf_simple *buf, uint16_t op,
|
|
|
|
bool vnd)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
2021-11-29 16:17:52 +01:00
|
|
|
struct mod_member_list_param *param;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t elem_addr, mod_id, cid;
|
|
|
|
uint8_t status;
|
2020-04-22 10:14:12 +02:00
|
|
|
int i;
|
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
if ((vnd && buf->len < 7U) || (buf->len < 5U)) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2020-04-22 10:14:12 +02:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
elem_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
if (vnd) {
|
|
|
|
cid = net_buf_simple_pull_le16(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_id = net_buf_simple_pull_le16(buf);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, op, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
2021-12-13 15:20:00 +08:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->elem_addr != elem_addr || param->mod_id != mod_id ||
|
2021-12-13 15:20:00 +08:00
|
|
|
(vnd && param->cid != cid)) {
|
2021-11-29 16:17:52 +01:00
|
|
|
BT_WARN("Model Member List parameters did not match");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (buf->len % 2) {
|
|
|
|
BT_WARN("Model Member List invalid length");
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-12-13 15:20:00 +08:00
|
|
|
if (param->member_cnt && param->members) {
|
|
|
|
|
|
|
|
for (i = 0; i < *param->member_cnt && buf->len; i++) {
|
|
|
|
param->members[i] = net_buf_simple_pull_le16(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
*param->member_cnt = i;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2020-04-22 10:14:12 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_app_list(struct bt_mesh_model *model,
|
2021-11-29 16:17:52 +01:00
|
|
|
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
return mod_member_list_handle(ctx, buf, OP_SIG_MOD_APP_LIST, false);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_app_list_vnd(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
return mod_member_list_handle(ctx, buf, OP_VND_MOD_APP_LIST, true);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 12:29:31 +02:00
|
|
|
struct mod_pub_param {
|
2021-11-29 16:17:52 +01:00
|
|
|
uint16_t mod_id;
|
|
|
|
uint16_t cid;
|
|
|
|
uint16_t elem_addr;
|
|
|
|
uint8_t *status;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_mod_pub *pub;
|
2017-11-16 12:29:31 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_pub_status(struct bt_mesh_model *model,
|
2021-11-29 16:17:52 +01:00
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
|
|
|
struct mod_pub_param *param;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint16_t mod_id, cid, elem_addr;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_mod_pub pub;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t status;
|
2017-11-16 12:29:31 +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));
|
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
if ((buf->len != 12U) && (buf->len != 14U)) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
elem_addr = net_buf_simple_pull_le16(buf);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
pub.addr = net_buf_simple_pull_le16(buf);
|
|
|
|
pub.app_idx = net_buf_simple_pull_le16(buf);
|
|
|
|
pub.cred_flag = (pub.app_idx & BIT(12));
|
|
|
|
pub.app_idx &= BIT_MASK(12);
|
|
|
|
pub.ttl = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.period = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.transmit = net_buf_simple_pull_u8(buf);
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (buf->len == 4U) {
|
|
|
|
cid = net_buf_simple_pull_le16(buf);
|
|
|
|
mod_id = net_buf_simple_pull_le16(buf);
|
|
|
|
} else {
|
2017-11-16 12:29:31 +02:00
|
|
|
cid = CID_NVAL;
|
2021-11-29 16:17:52 +01:00
|
|
|
mod_id = net_buf_simple_pull_le16(buf);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_PUB_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
|
|
|
if (mod_id != param->mod_id || cid != param->cid) {
|
|
|
|
BT_WARN("Mod Pub Model ID or Company ID mismatch");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (elem_addr != param->elem_addr) {
|
|
|
|
BT_WARN("Model Pub Status for unexpected element (0x%04x)", elem_addr);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->pub) {
|
|
|
|
*param->pub = pub;
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:51:28 +02:00
|
|
|
struct mod_sub_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
|
|
|
uint16_t elem_addr;
|
|
|
|
uint16_t *sub_addr;
|
|
|
|
uint16_t *expect_sub;
|
|
|
|
uint16_t mod_id;
|
|
|
|
uint16_t cid;
|
2017-11-12 23:51:28 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_sub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-12 23:51:28 +02:00
|
|
|
{
|
|
|
|
struct mod_sub_param *param;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint16_t elem_addr, sub_addr, mod_id, cid;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t status;
|
2022-06-17 17:37:26 +08:00
|
|
|
int err = 0;
|
2017-11-12 23:51:28 +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));
|
|
|
|
|
2021-04-27 15:59:54 +02:00
|
|
|
if ((buf->len != 7U) && (buf->len != 9U)) {
|
|
|
|
BT_ERR("The message size for the application opcode is incorrect.");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:51:28 +02:00
|
|
|
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);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_MOD_SUB_STATUS,
|
|
|
|
ctx->addr, (void **)¶m)) {
|
|
|
|
if (param->elem_addr != elem_addr || param->mod_id != mod_id ||
|
|
|
|
(param->expect_sub && *param->expect_sub != sub_addr) ||
|
|
|
|
param->cid != cid) {
|
|
|
|
BT_WARN("Model Subscription Status parameters did not match");
|
2022-06-17 17:37:26 +08:00
|
|
|
err = -ENOENT;
|
|
|
|
goto done;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2017-11-24 13:36:05 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->sub_addr) {
|
|
|
|
*param->sub_addr = sub_addr;
|
|
|
|
}
|
2017-11-12 23:51:28 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2022-06-17 17:37:26 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (cli->cb && cli->cb->mod_sub_status) {
|
|
|
|
cli->cb->mod_sub_status(cli, ctx->addr, status, elem_addr,
|
2022-07-08 11:09:02 +08:00
|
|
|
sub_addr, (cid << 16) | mod_id);
|
2022-06-17 17:37:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_sub_list(struct bt_mesh_model *model,
|
2021-11-29 16:17:52 +01:00
|
|
|
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
return mod_member_list_handle(ctx, buf, OP_MOD_SUB_LIST, false);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int mod_sub_list_vnd(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2020-04-22 10:14:12 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
return mod_member_list_handle(ctx, buf, OP_MOD_SUB_LIST_VND, true);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2017-11-13 00:22:09 +02:00
|
|
|
struct hb_sub_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_hb_sub *sub;
|
2017-11-13 00:22:09 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int hb_sub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-13 00:22:09 +02:00
|
|
|
{
|
|
|
|
struct hb_sub_param *param;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_hb_sub sub;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint8_t status;
|
2017-11-13 00:22:09 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
sub.src = net_buf_simple_pull_le16(buf);
|
|
|
|
sub.dst = net_buf_simple_pull_le16(buf);
|
|
|
|
sub.period = net_buf_simple_pull_u8(buf);
|
|
|
|
sub.count = net_buf_simple_pull_u8(buf);
|
|
|
|
sub.min = net_buf_simple_pull_u8(buf);
|
|
|
|
sub.max = net_buf_simple_pull_u8(buf);
|
|
|
|
|
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_SUB_STATUS,
|
|
|
|
ctx->addr, (void **)¶m)) {
|
2021-12-08 20:30:57 +08:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->sub) {
|
|
|
|
*param->sub = sub;
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2017-11-13 00:22:09 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 10:46:22 +02:00
|
|
|
struct hb_pub_param {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *status;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_hb_pub *pub;
|
2017-11-14 10:46:22 +02:00
|
|
|
};
|
|
|
|
|
2021-04-14 13:17:59 +02:00
|
|
|
static int hb_pub_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
2017-11-14 10:46:22 +02:00
|
|
|
{
|
|
|
|
struct hb_pub_param *param;
|
2021-11-29 16:17:52 +01:00
|
|
|
uint8_t status;
|
2022-08-30 13:51:34 +02:00
|
|
|
struct bt_mesh_cfg_cli_hb_pub pub;
|
2017-11-14 10:46:22 +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));
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.dst = net_buf_simple_pull_le16(buf);
|
|
|
|
pub.count = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.period = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.ttl = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.feat = net_buf_simple_pull_u8(buf);
|
|
|
|
pub.net_idx = net_buf_simple_pull_u8(buf);
|
|
|
|
|
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_HEARTBEAT_PUB_STATUS,
|
|
|
|
ctx->addr, (void **)¶m)) {
|
2021-12-08 20:19:35 +08:00
|
|
|
if (param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->pub) {
|
|
|
|
*param->pub = pub;
|
|
|
|
}
|
2017-11-16 12:50:13 +02:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
2017-11-16 12:50:13 +02:00
|
|
|
}
|
2021-04-14 13:17:59 +02:00
|
|
|
return 0;
|
2017-11-14 10:46:22 +02:00
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
struct node_idt_param {
|
|
|
|
uint8_t *status;
|
|
|
|
uint16_t net_idx;
|
|
|
|
uint8_t *identity;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int node_identity_status(struct bt_mesh_model *model,
|
|
|
|
struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct node_idt_param *param;
|
|
|
|
uint16_t net_idx, identity;
|
|
|
|
uint8_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));
|
|
|
|
|
|
|
|
status = net_buf_simple_pull_u8(buf);
|
|
|
|
net_idx = net_buf_simple_pull_le16(buf) & 0xfff;
|
|
|
|
identity = net_buf_simple_pull_u8(buf);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_NODE_IDENTITY_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
|
|
|
if (param && param->status) {
|
|
|
|
*param->status = status;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param && param->identity) {
|
|
|
|
*param->identity = identity;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2022-07-08 11:25:27 +08:00
|
|
|
if (cli->cb && cli->cb->node_identity_status) {
|
|
|
|
cli->cb->node_identity_status(cli, ctx->addr, status,
|
|
|
|
net_idx, identity);
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct lpn_timeout_param {
|
|
|
|
uint16_t unicast_addr;
|
|
|
|
int32_t *polltimeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int lpn_timeout_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
struct lpn_timeout_param *param;
|
|
|
|
uint16_t unicast_addr;
|
|
|
|
int32_t polltimeout;
|
2022-07-08 11:25:27 +08:00
|
|
|
int err;
|
2021-03-02 10:49:14 +01: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));
|
|
|
|
|
|
|
|
unicast_addr = net_buf_simple_pull_le16(buf);
|
|
|
|
polltimeout = net_buf_simple_pull_le24(buf);
|
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, OP_LPN_TIMEOUT_STATUS, ctx->addr,
|
|
|
|
(void **)¶m)) {
|
|
|
|
if (param->unicast_addr != unicast_addr) {
|
2022-07-08 11:25:27 +08:00
|
|
|
err = -ENOENT;
|
|
|
|
goto done;
|
2021-11-29 16:17:52 +01:00
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
if (param->polltimeout) {
|
|
|
|
*param->polltimeout = polltimeout;
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2021-11-29 16:17:52 +01:00
|
|
|
bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx);
|
|
|
|
}
|
2021-03-02 10:49:14 +01:00
|
|
|
|
2022-07-08 11:25:27 +08:00
|
|
|
err = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (cli->cb && cli->cb->lpn_timeout_status) {
|
|
|
|
cli->cb->lpn_timeout_status(cli, ctx->addr, unicast_addr,
|
|
|
|
polltimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2021-03-02 10:49:14 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 13:48:55 +02:00
|
|
|
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
|
2021-04-27 15:59:54 +02:00
|
|
|
{ OP_DEV_COMP_DATA_STATUS, BT_MESH_LEN_MIN(15), comp_data_status },
|
|
|
|
{ OP_BEACON_STATUS, BT_MESH_LEN_EXACT(1), beacon_status },
|
|
|
|
{ OP_DEFAULT_TTL_STATUS, BT_MESH_LEN_EXACT(1), ttl_status },
|
|
|
|
{ OP_FRIEND_STATUS, BT_MESH_LEN_EXACT(1), friend_status },
|
|
|
|
{ OP_GATT_PROXY_STATUS, BT_MESH_LEN_EXACT(1), gatt_proxy_status },
|
|
|
|
{ OP_RELAY_STATUS, BT_MESH_LEN_EXACT(2), relay_status },
|
|
|
|
{ OP_NET_TRANSMIT_STATUS, BT_MESH_LEN_EXACT(1), net_transmit_status },
|
|
|
|
{ OP_NET_KEY_STATUS, BT_MESH_LEN_EXACT(3), net_key_status },
|
|
|
|
{ OP_NET_KEY_LIST, BT_MESH_LEN_MIN(0), net_key_list },
|
|
|
|
{ OP_APP_KEY_STATUS, BT_MESH_LEN_EXACT(4), app_key_status },
|
|
|
|
{ OP_APP_KEY_LIST, BT_MESH_LEN_MIN(3), app_key_list },
|
|
|
|
{ OP_MOD_APP_STATUS, BT_MESH_LEN_MIN(7), mod_app_status },
|
|
|
|
{ OP_SIG_MOD_APP_LIST, BT_MESH_LEN_MIN(5), mod_app_list },
|
|
|
|
{ OP_VND_MOD_APP_LIST, BT_MESH_LEN_MIN(7), mod_app_list_vnd },
|
|
|
|
{ OP_MOD_PUB_STATUS, BT_MESH_LEN_MIN(12), mod_pub_status },
|
|
|
|
{ OP_MOD_SUB_STATUS, BT_MESH_LEN_MIN(7), mod_sub_status },
|
|
|
|
{ OP_MOD_SUB_LIST, BT_MESH_LEN_MIN(5), mod_sub_list },
|
|
|
|
{ OP_MOD_SUB_LIST_VND, BT_MESH_LEN_MIN(7), mod_sub_list_vnd },
|
|
|
|
{ OP_HEARTBEAT_SUB_STATUS, BT_MESH_LEN_EXACT(9), hb_sub_status },
|
|
|
|
{ OP_HEARTBEAT_PUB_STATUS, BT_MESH_LEN_EXACT(10), hb_pub_status },
|
|
|
|
{ OP_NODE_RESET_STATUS, BT_MESH_LEN_EXACT(0), node_reset_status },
|
2021-03-02 10:49:14 +01:00
|
|
|
{ OP_NODE_IDENTITY_STATUS, BT_MESH_LEN_EXACT(4), node_identity_status},
|
|
|
|
{ OP_LPN_TIMEOUT_STATUS, BT_MESH_LEN_EXACT(5), lpn_timeout_status },
|
|
|
|
{ OP_KRP_STATUS, BT_MESH_LEN_EXACT(4), krp_status},
|
2017-11-12 13:48:55 +02:00
|
|
|
BT_MESH_MODEL_OP_END,
|
|
|
|
};
|
2017-11-12 17:47:00 +02:00
|
|
|
|
2019-08-19 10:05:36 +02:00
|
|
|
static int cfg_cli_init(struct bt_mesh_model *model)
|
|
|
|
{
|
|
|
|
if (!bt_mesh_model_in_primary(model)) {
|
|
|
|
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;
|
2022-04-13 12:16:59 +02:00
|
|
|
msg_timeout = CONFIG_BT_MESH_CFG_CLI_TIMEOUT;
|
2019-08-19 10:05:36 +02:00
|
|
|
|
2019-07-12 15:57:58 +02:00
|
|
|
/*
|
|
|
|
* Configuration Model security is device-key based and both the local
|
|
|
|
* and remote keys are allowed to access this model.
|
|
|
|
*/
|
|
|
|
model->keys[0] = BT_MESH_KEY_DEV_ANY;
|
2019-08-19 10:05:36 +02:00
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_init(&cli->ack_ctx);
|
2019-08-19 10:05:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb = {
|
|
|
|
.init = cfg_cli_init,
|
|
|
|
};
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
static int cli_prepare(void *param, uint32_t op, uint16_t addr)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
|
|
|
if (!cli) {
|
|
|
|
BT_ERR("No available Configuration Client context!");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_prepare(&cli->ack_ctx, op, addr, param);
|
2017-11-22 18:51:45 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, uint8_t *rsp,
|
|
|
|
struct net_buf_simple *comp)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_comp_data_get(net_idx, addr, page, rsp, comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_beacon_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_beacon_get(net_idx, addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_krp_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, uint8_t *status,
|
|
|
|
uint8_t *phase)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_krp_get(net_idx, addr, key_net_idx, status, phase);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_krp_set(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, uint8_t transition,
|
|
|
|
uint8_t *status, uint8_t *phase)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_krp_set(net_idx, addr, key_net_idx, transition, status, phase);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_beacon_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_beacon_set(net_idx, addr, val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_ttl_get(uint16_t net_idx, uint16_t addr, uint8_t *ttl)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_ttl_get(net_idx, addr, ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_ttl_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *ttl)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_ttl_set(net_idx, addr, val, ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_friend_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_friend_get(net_idx, addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_friend_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_friend_set(net_idx, addr, val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_gatt_proxy_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_gatt_proxy_get(net_idx, addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_gatt_proxy_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_gatt_proxy_set(net_idx, addr, val, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_transmit_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *transmit)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_transmit_set(net_idx, addr, val, transmit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_transmit_get(uint16_t net_idx, uint16_t addr, uint8_t *transmit)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_transmit_get(net_idx, addr, transmit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_relay_get(uint16_t net_idx, uint16_t addr, uint8_t *status, uint8_t *transmit)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_relay_get(net_idx, addr, status, transmit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_relay_set(uint16_t net_idx, uint16_t addr, uint8_t new_relay, uint8_t new_transmit,
|
|
|
|
uint8_t *status, uint8_t *transmit)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_relay_set(net_idx, addr, new_relay, new_transmit, status, transmit);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
const uint8_t net_key[16], uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_key_add(net_idx, addr, key_net_idx, net_key, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_key_update(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
const uint8_t net_key[16], uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_key_update(net_idx, addr, key_net_idx, net_key, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_key_get(uint16_t net_idx, uint16_t addr, uint16_t *keys, size_t *key_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_key_get(net_idx, addr, keys, key_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_net_key_del(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_net_key_del(net_idx, addr, key_net_idx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, const uint8_t app_key[16], uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_app_key_add(net_idx, addr, key_net_idx, key_app_idx, app_key,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_app_key_update(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, const uint8_t app_key[16], uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_app_key_update(net_idx, addr, key_net_idx, key_app_idx, app_key,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_node_reset(net_idx, addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, uint8_t *status,
|
|
|
|
uint16_t *keys, size_t *key_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_app_key_get(net_idx, addr, key_net_idx, status, keys, key_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_app_key_del(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_app_key_del(net_idx, addr, key_net_idx, key_app_idx, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_bind(net_idx, addr, elem_addr, mod_app_idx, mod_id, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_bind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_bind_vnd(net_idx, addr, elem_addr, mod_app_idx, mod_id, cid,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_unbind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_unbind(net_idx, addr, elem_addr, mod_app_idx, mod_id,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_unbind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_unbind_vnd(net_idx, addr, elem_addr, mod_app_idx, mod_id,
|
|
|
|
cid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
uint8_t *status, uint16_t *apps, size_t *app_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_get(net_idx, addr, elem_addr, mod_id, status, apps, app_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_app_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status, uint16_t *apps,
|
|
|
|
size_t *app_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_app_get_vnd(net_idx, addr, elem_addr, mod_id, cid, status, apps,
|
|
|
|
app_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t sub_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_add(net_idx, addr, elem_addr, sub_addr, mod_id, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_add_vnd(net_idx, addr, elem_addr, sub_addr, mod_id, cid,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t sub_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_del(net_idx, addr, elem_addr, sub_addr, mod_id, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del_all(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_del_all(net_idx, addr, elem_addr, mod_id, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_del_vnd(net_idx, addr, elem_addr, sub_addr, mod_id, cid,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_del_all_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_del_all_vnd(net_idx, addr, elem_addr, mod_id, cid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_overwrite(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_overwrite(net_idx, addr, elem_addr, sub_addr, mod_id,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_overwrite_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_overwrite_vnd(net_idx, addr, elem_addr, sub_addr, mod_id,
|
|
|
|
cid, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_add(net_idx, addr, elem_addr, label, mod_id, virt_addr,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_add_vnd(net_idx, addr, elem_addr, label, mod_id, cid,
|
|
|
|
virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_del(net_idx, addr, elem_addr, label, mod_id, virt_addr,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_del_vnd(net_idx, addr, elem_addr, label, mod_id, cid,
|
|
|
|
virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_overwrite(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_overwrite(net_idx, addr, elem_addr, label, mod_id,
|
|
|
|
virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_va_overwrite_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_va_overwrite_vnd(net_idx, addr, elem_addr, label, mod_id,
|
|
|
|
cid, virt_addr, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
uint8_t *status, uint16_t *subs, size_t *sub_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_get(net_idx, addr, elem_addr, mod_id, status, subs, sub_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_sub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status, uint16_t *subs,
|
|
|
|
size_t *sub_cnt)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_sub_get_vnd(net_idx, addr, elem_addr, mod_id, cid, status, subs,
|
|
|
|
sub_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_pub_get(net_idx, addr, elem_addr, mod_id,
|
|
|
|
(struct bt_mesh_cfg_cli_mod_pub *)pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, struct bt_mesh_cfg_mod_pub *pub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_pub_get_vnd(net_idx, addr, elem_addr, mod_id, cid,
|
|
|
|
(struct bt_mesh_cfg_cli_mod_pub *)pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
struct bt_mesh_cfg_mod_pub *pub, uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_pub_set(net_idx, addr, elem_addr, mod_id,
|
|
|
|
(struct bt_mesh_cfg_cli_mod_pub *)pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_mod_pub_set_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, struct bt_mesh_cfg_mod_pub *pub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_mod_pub_set_vnd(net_idx, addr, elem_addr, mod_id, cid,
|
|
|
|
(struct bt_mesh_cfg_cli_mod_pub *)pub, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_hb_sub_set(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_hb_sub *sub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_hb_sub_set(net_idx, addr, (struct bt_mesh_cfg_cli_hb_sub *)sub,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_hb_sub_get(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_hb_sub *sub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_hb_sub_get(net_idx, addr, (struct bt_mesh_cfg_cli_hb_sub *)sub,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_hb_pub_set(uint16_t net_idx, uint16_t addr, const struct bt_mesh_cfg_hb_pub *pub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_hb_pub_set(net_idx, addr, (struct bt_mesh_cfg_cli_hb_pub *)pub,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_hb_pub_get(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_hb_pub *pub,
|
|
|
|
uint8_t *status)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_hb_pub_get(net_idx, addr, (struct bt_mesh_cfg_cli_hb_pub *)pub,
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_node_identity_set(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t new_identity, uint8_t *status, uint8_t *identity)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_node_identity_set(net_idx, addr, key_net_idx, new_identity, status,
|
|
|
|
identity);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_node_identity_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t *status, uint8_t *identity)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_node_identity_get(net_idx, addr, key_net_idx, status, identity);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_lpn_timeout_get(uint16_t net_idx, uint16_t addr, uint16_t unicast_addr,
|
|
|
|
int32_t *polltimeout)
|
|
|
|
{
|
|
|
|
return bt_mesh_cfg_cli_lpn_timeout_get(net_idx, addr, unicast_addr, polltimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bt_mesh_cfg_cli_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page, uint8_t *rsp,
|
|
|
|
struct net_buf_simple *comp)
|
2017-11-12 17:47:00 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_DEV_COMP_DATA_GET, 1);
|
2017-11-12 17:47:00 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 17:47:00 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct comp_data param = {
|
2021-03-23 14:35:03 +01:00
|
|
|
.page = rsp,
|
2017-11-12 17:47:00 +02:00
|
|
|
.comp = comp,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_DEV_COMP_DATA_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 17:47:00 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!rsp && !comp) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 17:47:00 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int get_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t rsp, uint8_t *val)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 0);
|
2017-11-12 18:33:47 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 18:33:47 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(val, rsp, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 18:33:47 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!val) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int set_state_u8(uint16_t net_idx, uint16_t addr, uint32_t op, uint32_t rsp, uint8_t new_val,
|
|
|
|
uint8_t *val)
|
2017-11-12 18:33:47 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 1);
|
2017-11-12 18:33:47 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 18:33:47 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(val, rsp, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 18:33:47 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!val) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 18:33:47 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_beacon_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return get_state_u8(net_idx, addr, OP_BEACON_GET, OP_BEACON_STATUS, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_krp_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx, uint8_t *status,
|
|
|
|
uint8_t *phase)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_GET, 2);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct krp_param param = {
|
|
|
|
.status = status,
|
|
|
|
.phase = phase,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_KRP_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_KRP_GET);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !phase) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_krp_set(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t transition, uint8_t *status, uint8_t *phase)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_SET, 3);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct krp_param param = {
|
|
|
|
.status = status,
|
|
|
|
.phase = phase,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_KRP_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_KRP_SET);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
net_buf_simple_add_u8(&msg, transition);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !phase) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_beacon_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return set_state_u8(net_idx, addr, OP_BEACON_SET, OP_BEACON_STATUS, val, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_ttl_get(uint16_t net_idx, uint16_t addr, uint8_t *ttl)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return get_state_u8(net_idx, addr, OP_DEFAULT_TTL_GET, OP_DEFAULT_TTL_STATUS, ttl);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_ttl_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *ttl)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return set_state_u8(net_idx, addr, OP_DEFAULT_TTL_SET, OP_DEFAULT_TTL_STATUS, val, ttl);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_friend_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return get_state_u8(net_idx, addr, OP_FRIEND_GET, OP_FRIEND_STATUS, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_friend_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return set_state_u8(net_idx, addr, OP_FRIEND_SET, OP_FRIEND_STATUS, val, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_gatt_proxy_get(uint16_t net_idx, uint16_t addr, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return get_state_u8(net_idx, addr, OP_GATT_PROXY_GET, OP_GATT_PROXY_STATUS, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_gatt_proxy_set(uint16_t net_idx, uint16_t addr, uint8_t val, uint8_t *status)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return set_state_u8(net_idx, addr, OP_GATT_PROXY_SET, OP_GATT_PROXY_STATUS, val, status);
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_transmit_set(uint16_t net_idx, uint16_t addr, uint8_t val,
|
|
|
|
uint8_t *transmit)
|
2020-09-23 10:50:23 +08:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return set_state_u8(net_idx, addr, OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS, val,
|
|
|
|
transmit);
|
2020-09-23 10:50:23 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_transmit_get(uint16_t net_idx, uint16_t addr, uint8_t *transmit)
|
2020-09-23 10:50:23 +08:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return get_state_u8(net_idx, addr, OP_NET_TRANSMIT_GET, OP_NET_TRANSMIT_STATUS, transmit);
|
2020-09-23 10:50:23 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_relay_get(uint16_t net_idx, uint16_t addr, uint8_t *status, uint8_t *transmit)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_GET, 0);
|
2017-11-12 21:10:05 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 21:10:05 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct relay_param param = {
|
|
|
|
.status = status,
|
|
|
|
.transmit = transmit,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_RELAY_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 21:10:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !transmit) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_relay_set(uint16_t net_idx, uint16_t addr, uint8_t new_relay,
|
|
|
|
uint8_t new_transmit, uint8_t *status, uint8_t *transmit)
|
2017-11-12 21:10:05 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2);
|
2017-11-12 21:10:05 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 21:10:05 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct relay_param param = {
|
|
|
|
.status = status,
|
|
|
|
.transmit = transmit,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_RELAY_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 21:10:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !transmit) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 21:10:05 +02:00
|
|
|
}
|
2017-11-12 18:33:47 +02:00
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
const uint8_t net_key[16], uint8_t *status)
|
2017-12-01 10:54:38 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18);
|
2017-12-01 10:54:38 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-12-01 10:54:38 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct net_key_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_NET_KEY_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-12-01 10:54:38 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-12-01 10:54:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-12-01 10:54:38 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_key_update(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
const uint8_t net_key[16], uint8_t *status)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct net_key_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_NET_KEY_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NET_KEY_UPDATE);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
net_buf_simple_add_mem(&msg, net_key, 16);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_key_get(uint16_t net_idx, uint16_t addr, uint16_t *keys, size_t *key_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_GET, 0);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct net_key_list_param param = {
|
|
|
|
.keys = keys,
|
|
|
|
.key_cnt = key_cnt,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_NET_KEY_LIST, addr);
|
2020-04-22 10:14:12 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NET_KEY_GET);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-04-22 10:14:12 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!keys || !key_cnt) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_net_key_del(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t *status)
|
2020-08-27 10:37:48 +02:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_DEL, 2);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct net_key_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_NET_KEY_STATUS, addr);
|
2020-08-27 10:37:48 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NET_KEY_DEL);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-08-27 10:37:48 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-08-27 10:37:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-08-27 10:37:48 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, const uint8_t app_key[16], uint8_t *status)
|
2017-11-12 23:04:36 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19);
|
2017-11-12 23:04:36 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 23:04:36 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-23 09:47:29 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-23 09:47:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-09-23 09:47:29 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_app_key_update(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, const uint8_t app_key[16], uint8_t *status)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.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;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_APP_KEY_UPDATE);
|
|
|
|
key_idx_pack(&msg, key_net_idx, key_app_idx);
|
|
|
|
net_buf_simple_add_mem(&msg, app_key, 16);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_node_reset(uint16_t net_idx, uint16_t addr, bool *status)
|
2020-09-23 09:47:29 +08:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_RESET, 0);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
*status = false;
|
|
|
|
}
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(status, OP_NODE_RESET_STATUS, addr);
|
2020-09-23 09:47:29 +08:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NODE_RESET);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 23:04:36 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:38:44 +02:00
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 23:38:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 23:04:36 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t *status, uint16_t *keys, size_t *key_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_GET, 2);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct app_key_list_param param = {
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
.status = status,
|
|
|
|
.keys = keys,
|
|
|
|
.key_cnt = key_cnt,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_APP_KEY_LIST, addr);
|
2020-04-22 10:14:12 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_APP_KEY_GET);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-04-22 10:14:12 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && (!keys || !key_cnt)) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_app_key_del(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint16_t key_app_idx, uint8_t *status)
|
2020-09-02 20:45:07 +08:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
|
2020-09-02 20:45:07 +08:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_APP_KEY_DEL);
|
|
|
|
key_idx_pack(&msg, key_net_idx, key_app_idx);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-02 20:45:07 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-02 20:45:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-09-02 20:45:07 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_app_idx,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status)
|
2017-11-12 23:38:44 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8);
|
2017-11-12 23:38:44 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 23:38:44 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_APP_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 23:38:44 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 23:38:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_bind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint8_t *status)
|
2017-11-12 23:38:44 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_app_bind(net_idx, addr, elem_addr, mod_app_idx, mod_id, CID_NVAL, status);
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_bind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
2017-11-12 23:38:44 +02:00
|
|
|
{
|
2017-11-16 10:28:33 +02:00
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_app_bind(net_idx, addr, elem_addr, mod_app_idx, mod_id, cid, status);
|
2017-11-12 23:38:44 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_app_unbind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_app_idx,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status)
|
2020-09-02 20:45:07 +08:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_APP_STATUS, addr);
|
2020-09-02 20:45:07 +08:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_MOD_APP_UNBIND);
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_le16(&msg, mod_app_idx);
|
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-02 20:45:07 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-09-02 20:45:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-09-02 20:45:07 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_unbind(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint8_t *status)
|
2020-09-02 20:45:07 +08:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_app_unbind(net_idx, addr, elem_addr, mod_app_idx, mod_id, CID_NVAL, status);
|
2020-09-02 20:45:07 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_unbind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
2020-09-02 20:45:07 +08:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_app_unbind(net_idx, addr, elem_addr, mod_app_idx, mod_id, cid, status);
|
2020-09-02 20:45:07 +08:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_member_list_get(uint32_t op, uint32_t expect_op, uint16_t net_idx, uint16_t addr,
|
|
|
|
uint16_t elem_addr, uint16_t mod_id, uint16_t cid, uint8_t *status,
|
|
|
|
uint16_t *apps, size_t *app_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct mod_member_list_param param = {
|
|
|
|
.status = status,
|
|
|
|
.elem_addr = elem_addr,
|
|
|
|
.mod_id = mod_id,
|
|
|
|
.cid = cid,
|
|
|
|
.members = apps,
|
|
|
|
.member_cnt = app_cnt,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, expect_op, addr);
|
2020-04-22 10:14:12 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x", net_idx, addr, elem_addr);
|
2020-04-22 10:14:12 +02:00
|
|
|
BT_DBG("mod_id 0x%04x cid 0x%04x op: %x", mod_id, cid, op);
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, op);
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-04-22 10:14:12 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && (!apps || !app_cnt)) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status, uint16_t *apps, size_t *app_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_member_list_get(OP_SIG_MOD_APP_GET, OP_SIG_MOD_APP_LIST, net_idx, addr,
|
|
|
|
elem_addr, mod_id, CID_NVAL, status, apps, app_cnt);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_app_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status, uint16_t *apps,
|
|
|
|
size_t *app_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_member_list_get(OP_VND_MOD_APP_GET, OP_VND_MOD_APP_LIST, net_idx, addr,
|
|
|
|
elem_addr, mod_id, cid, status, apps, app_cnt);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int mod_sub(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid, uint8_t *status)
|
2017-11-12 23:51:28 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 8);
|
2017-11-12 23:51:28 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-12 23:51:28 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_SUB_STATUS, addr);
|
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);
|
2021-08-10 16:44:17 +02:00
|
|
|
|
|
|
|
if (sub_addr != BT_MESH_ADDR_UNASSIGNED) {
|
|
|
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-12 23:51:28 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-11-24 16:16:02 +01:00
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2020-11-24 16:16:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-12 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint8_t *status)
|
2017-11-12 23:51:28 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if (!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) {
|
2021-08-10 16:44:17 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +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
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
2017-11-12 23:51:28 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if ((!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) ||
|
2022-08-30 13:51:34 +02:00
|
|
|
cid == CID_NVAL) {
|
2017-11-16 10:28:33 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_ADD, net_idx, addr, elem_addr, sub_addr, mod_id, cid, status);
|
2017-11-18 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint8_t *status)
|
2017-11-18 11:52:21 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if (!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) {
|
2021-08-10 16:44:17 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_DEL, net_idx, addr, elem_addr, sub_addr, mod_id, CID_NVAL,
|
|
|
|
status);
|
2017-11-18 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_del_all(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_DEL_ALL, net_idx, addr, elem_addr, BT_MESH_ADDR_UNASSIGNED,
|
|
|
|
mod_id, CID_NVAL, status);
|
2021-03-02 10:49:14 +01:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
2017-11-18 11:52:21 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if ((!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) ||
|
2022-08-30 13:51:34 +02:00
|
|
|
cid == CID_NVAL) {
|
2017-11-18 11:52:21 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_DEL, net_idx, addr, elem_addr, sub_addr, mod_id, cid, status);
|
2017-11-18 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_del_all_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status)
|
2021-08-10 16:44:17 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_DEL_ALL, net_idx, addr, elem_addr, BT_MESH_ADDR_UNASSIGNED,
|
|
|
|
mod_id, cid, status);
|
2021-08-10 16:44:17 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_overwrite(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint8_t *status)
|
2017-11-18 11:52:21 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if (!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) {
|
2021-08-10 16:44:17 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub(OP_MOD_SUB_OVERWRITE, net_idx, addr, elem_addr, sub_addr, mod_id, CID_NVAL,
|
|
|
|
status);
|
2017-11-18 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_overwrite_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t sub_addr, uint16_t mod_id, uint16_t cid,
|
|
|
|
uint8_t *status)
|
2017-11-18 11:52:21 +02:00
|
|
|
{
|
2022-04-20 10:35:44 +02:00
|
|
|
if ((!BT_MESH_ADDR_IS_GROUP(sub_addr) && !BT_MESH_ADDR_IS_FIXED_GROUP(sub_addr)) ||
|
2022-08-30 13:51:34 +02:00
|
|
|
cid == CID_NVAL) {
|
2017-11-18 11:52:21 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int mod_sub_va(uint32_t op, uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
2022-08-30 13:51:34 +02:00
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 22);
|
2017-11-24 13:36:05 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-24 13:36:05 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_SUB_STATUS, addr);
|
2017-11-24 13:36:05 +02:00
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x label %s", net_idx, addr, elem_addr,
|
|
|
|
bt_hex(label, 16));
|
2017-11-24 13:36:05 +02:00
|
|
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-24 13:36:05 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !virt_addr) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-24 13:36:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_add(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_ADD, net_idx, addr, elem_addr, label, mod_id, CID_NVAL,
|
|
|
|
virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_add_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_ADD, net_idx, addr, elem_addr, label, mod_id, cid,
|
|
|
|
virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_del(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t *virt_addr,
|
|
|
|
uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_DEL, net_idx, addr, elem_addr, label, mod_id, CID_NVAL,
|
|
|
|
virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_del_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_DEL, net_idx, addr, elem_addr, label, mod_id, cid,
|
|
|
|
virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_overwrite(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, net_idx, addr, elem_addr, label, mod_id,
|
|
|
|
CID_NVAL, virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_va_overwrite_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
const uint8_t label[16], uint16_t mod_id, uint16_t cid,
|
|
|
|
uint16_t *virt_addr, uint8_t *status)
|
2017-11-24 13:36:05 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, net_idx, addr, elem_addr, label, mod_id, cid,
|
|
|
|
virt_addr, status);
|
2017-11-24 13:36:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint8_t *status, uint16_t *subs, size_t *sub_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_member_list_get(OP_MOD_SUB_GET, OP_MOD_SUB_LIST, net_idx, addr, elem_addr,
|
|
|
|
mod_id, CID_NVAL, status, subs, sub_cnt);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_sub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid, uint8_t *status, uint16_t *subs,
|
|
|
|
size_t *sub_cnt)
|
2020-04-22 10:14:12 +02:00
|
|
|
{
|
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_member_list_get(OP_MOD_SUB_GET_VND, OP_MOD_SUB_LIST_VND, net_idx, addr,
|
|
|
|
elem_addr, mod_id, cid, status, subs, sub_cnt);
|
2020-04-22 10:14:12 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
uint16_t cid, struct bt_mesh_cfg_cli_mod_pub *pub, uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6);
|
2017-11-16 12:29:31 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-16 12:29:31 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_PUB_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-16 12:29:31 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !pub) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-16 12:29:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_pub_get(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, struct bt_mesh_cfg_cli_mod_pub *pub,
|
|
|
|
uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
2022-08-30 13:51:34 +02:00
|
|
|
return mod_pub_get(net_idx, addr, elem_addr, mod_id, CID_NVAL, pub, status);
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_pub_get_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid,
|
|
|
|
struct bt_mesh_cfg_cli_mod_pub *pub, uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
uint16_t cid, struct bt_mesh_cfg_cli_mod_pub *pub, uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13);
|
2017-11-16 12:29:31 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-16 12:29:31 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_MOD_PUB_STATUS, addr);
|
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);
|
2019-11-14 02:49:38 -08:00
|
|
|
net_buf_simple_add_le16(&msg, (pub->app_idx | (pub->cred_flag << 12)));
|
2018-02-10 10:32:58 +02:00
|
|
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-16 12:29:31 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-16 12:29:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
static int mod_pub_va_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr, uint16_t mod_id,
|
|
|
|
uint16_t cid, struct bt_mesh_cfg_cli_mod_pub *pub, uint8_t *status)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.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;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_MOD_PUB_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
BT_DBG("app_idx 0x%04x", pub->app_idx);
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_MOD_PUB_VA_SET);
|
|
|
|
|
|
|
|
net_buf_simple_add_le16(&msg, elem_addr);
|
|
|
|
net_buf_simple_add_mem(&msg, pub->uuid, 16);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (cid != CID_NVAL) {
|
|
|
|
net_buf_simple_add_le16(&msg, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_buf_simple_add_le16(&msg, mod_id);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_pub_set(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, struct bt_mesh_cfg_cli_mod_pub *pub,
|
|
|
|
uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!pub) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
if (pub->uuid) {
|
|
|
|
return mod_pub_va_set(net_idx, addr, elem_addr, mod_id, CID_NVAL, pub, status);
|
|
|
|
} else {
|
|
|
|
return mod_pub_set(net_idx, addr, elem_addr, mod_id, CID_NVAL, pub, status);
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_mod_pub_set_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_addr,
|
|
|
|
uint16_t mod_id, uint16_t cid,
|
|
|
|
struct bt_mesh_cfg_cli_mod_pub *pub, uint8_t *status)
|
2017-11-16 12:29:31 +02:00
|
|
|
{
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!pub) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:29:31 +02:00
|
|
|
if (cid == CID_NVAL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
if (pub->uuid) {
|
|
|
|
return mod_pub_va_set(net_idx, addr, elem_addr, mod_id, cid, pub, status);
|
|
|
|
} else {
|
|
|
|
return mod_pub_set(net_idx, addr, elem_addr, mod_id, cid, pub, status);
|
|
|
|
}
|
2017-11-16 12:29:31 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_hb_sub_set(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_cli_hb_sub *sub,
|
|
|
|
uint8_t *status)
|
2017-11-13 00:22:09 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5);
|
2017-11-13 00:22:09 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-13 00:22:09 +02:00
|
|
|
.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;
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!sub) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 20:42:48 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 20:42:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-14 20:42:48 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_hb_sub_get(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_cli_hb_sub *sub,
|
|
|
|
uint8_t *status)
|
2017-11-14 20:42:48 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_GET, 0);
|
2017-11-14 20:42:48 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-14 20:42:48 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_SUB_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-13 00:22:09 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !sub) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-13 00:22:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-13 00:22:09 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_hb_pub_set(uint16_t net_idx, uint16_t addr,
|
|
|
|
const struct bt_mesh_cfg_cli_hb_pub *pub, uint8_t *status)
|
2017-11-14 10:46:22 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9);
|
2017-11-14 10:46:22 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-14 10:46:22 +02:00
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct hb_pub_param param = {
|
|
|
|
.status = status,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!pub) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 10:46:22 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 10:46:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-14 10:46:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_hb_pub_get(uint16_t net_idx, uint16_t addr, struct bt_mesh_cfg_cli_hb_pub *pub,
|
|
|
|
uint8_t *status)
|
2017-11-14 20:18:04 +02:00
|
|
|
{
|
2019-10-08 09:39:48 +02:00
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_GET, 0);
|
2017-11-14 20:18:04 +02:00
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
2019-07-12 15:57:58 +02:00
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
2017-11-14 20:18:04 +02:00
|
|
|
.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;
|
|
|
|
|
2021-03-24 12:59:45 +01:00
|
|
|
err = cli_prepare(¶m, OP_HEARTBEAT_PUB_STATUS, addr);
|
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);
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 20:18:04 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !pub) {
|
2021-03-24 17:38:03 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
2017-11-14 20:18:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:38:03 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
2017-11-14 20:18:04 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_node_identity_set(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t new_identity, uint8_t *status, uint8_t *identity)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_SET, 4);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct node_idt_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
.identity = identity,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_NODE_IDENTITY_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NODE_IDENTITY_SET);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
net_buf_simple_add_u8(&msg, new_identity);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !identity) {
|
2021-03-02 10:49:14 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_node_identity_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
|
|
|
|
uint8_t *status, uint8_t *identity)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_GET, 2);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct node_idt_param param = {
|
|
|
|
.status = status,
|
|
|
|
.net_idx = key_net_idx,
|
|
|
|
.identity = identity,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_NODE_IDENTITY_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_NODE_IDENTITY_GET);
|
|
|
|
net_buf_simple_add_le16(&msg, key_net_idx);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!status && !identity) {
|
2021-03-02 10:49:14 +01:00
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2022-08-30 13:51:34 +02:00
|
|
|
int bt_mesh_cfg_cli_lpn_timeout_get(uint16_t net_idx, uint16_t addr, uint16_t unicast_addr,
|
|
|
|
int32_t *polltimeout)
|
2021-03-02 10:49:14 +01:00
|
|
|
{
|
|
|
|
BT_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_GET, 2);
|
|
|
|
struct bt_mesh_msg_ctx ctx = {
|
|
|
|
.net_idx = net_idx,
|
|
|
|
.app_idx = BT_MESH_KEY_DEV_REMOTE,
|
|
|
|
.addr = addr,
|
|
|
|
.send_ttl = BT_MESH_TTL_DEFAULT,
|
|
|
|
};
|
|
|
|
struct lpn_timeout_param param = {
|
|
|
|
.unicast_addr = unicast_addr,
|
|
|
|
.polltimeout = polltimeout,
|
|
|
|
};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cli_prepare(¶m, OP_LPN_TIMEOUT_STATUS, addr);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_model_msg_init(&msg, OP_LPN_TIMEOUT_GET);
|
|
|
|
net_buf_simple_add_le16(&msg, unicast_addr);
|
|
|
|
|
|
|
|
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("model_send() failed (err %d)", err);
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:05:43 +01:00
|
|
|
if (!polltimeout) {
|
|
|
|
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:49:14 +01:00
|
|
|
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
int32_t bt_mesh_cfg_cli_timeout_get(void)
|
2017-11-14 20:45:26 +02:00
|
|
|
{
|
|
|
|
return msg_timeout;
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
void bt_mesh_cfg_cli_timeout_set(int32_t timeout)
|
2017-11-14 20:45:26 +02:00
|
|
|
{
|
|
|
|
msg_timeout = timeout;
|
|
|
|
}
|
2021-03-23 14:50:09 +01:00
|
|
|
|
|
|
|
int bt_mesh_comp_p0_get(struct bt_mesh_comp_p0 *page,
|
|
|
|
struct net_buf_simple *buf)
|
|
|
|
{
|
|
|
|
if (buf->len < 10) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
page->cid = net_buf_simple_pull_le16(buf);
|
|
|
|
page->pid = net_buf_simple_pull_le16(buf);
|
|
|
|
page->vid = net_buf_simple_pull_le16(buf);
|
|
|
|
page->crpl = net_buf_simple_pull_le16(buf);
|
|
|
|
page->feat = net_buf_simple_pull_le16(buf);
|
|
|
|
page->_buf = buf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bt_mesh_comp_p0_elem *bt_mesh_comp_p0_elem_pull(const struct bt_mesh_comp_p0 *page,
|
|
|
|
struct bt_mesh_comp_p0_elem *elem)
|
|
|
|
{
|
|
|
|
size_t modlist_size;
|
|
|
|
|
|
|
|
if (page->_buf->len < 4) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
elem->loc = net_buf_simple_pull_le16(page->_buf);
|
|
|
|
elem->nsig = net_buf_simple_pull_u8(page->_buf);
|
|
|
|
elem->nvnd = net_buf_simple_pull_u8(page->_buf);
|
|
|
|
|
|
|
|
modlist_size = elem->nsig * 2 + elem->nvnd * 4;
|
|
|
|
|
|
|
|
if (page->_buf->len < modlist_size) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
elem->_buf = net_buf_simple_pull_mem(page->_buf, modlist_size);
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t bt_mesh_comp_p0_elem_mod(struct bt_mesh_comp_p0_elem *elem, int idx)
|
|
|
|
{
|
|
|
|
CHECKIF(idx >= elem->nsig) {
|
|
|
|
return 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sys_get_le16(&elem->_buf[idx * 2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bt_mesh_mod_id_vnd bt_mesh_comp_p0_elem_mod_vnd(struct bt_mesh_comp_p0_elem *elem, int idx)
|
|
|
|
{
|
|
|
|
CHECKIF(idx >= elem->nvnd) {
|
|
|
|
return (struct bt_mesh_mod_id_vnd){ 0xffff, 0xffff };
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t offset = elem->nsig * 2 + idx * 4;
|
|
|
|
struct bt_mesh_mod_id_vnd mod = {
|
|
|
|
.company = sys_get_le16(&elem->_buf[offset]),
|
|
|
|
.id = sys_get_le16(&elem->_buf[offset + 2]),
|
|
|
|
};
|
|
|
|
|
|
|
|
return mod;
|
|
|
|
}
|