mesh: Add Config Client API

The api is used to reset a node (other than a Provisioner) and
remove it from the network

this is port of c9be68532c0d19a721b95dfdc2170c321c3f1cc6
This commit is contained in:
Krzysztof Kopyściński
2021-01-12 14:05:19 +01:00
committed by Łukasz Rymanowski
parent 53a5897000
commit 819bbe85fb
3 changed files with 90 additions and 3 deletions
+2
View File
@@ -37,6 +37,8 @@ extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb;
BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_op, NULL, \
cli_data, &bt_mesh_cfg_cli_cb)
int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status);
int bt_mesh_cfg_comp_data_get(uint16_t net_idx, uint16_t addr, uint8_t page,
uint8_t *status, struct os_mbuf *comp);
+59
View File
@@ -210,6 +210,26 @@ static void net_key_list(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync);
}
static void node_reset_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct os_mbuf *buf)
{
bool *param = NULL;
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x",
ctx->net_idx, ctx->app_idx, ctx->addr);
if (cli->op_pending != OP_NODE_RESET_STATUS) {
BT_WARN("Unexpected Node Reset Status message");
return;
}
param = cli->op_param;
if (param) {
*param = true;
}
k_sem_give(&cli->op_sync);
}
struct app_key_param {
uint8_t *status;
uint16_t net_idx;
@@ -686,6 +706,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
{ OP_MOD_SUB_LIST_VND, 7, mod_sub_list_vnd},
{ OP_HEARTBEAT_SUB_STATUS, 9, hb_sub_status },
{ OP_HEARTBEAT_PUB_STATUS, 10, hb_pub_status },
{ OP_NODE_RESET_STATUS, 0, node_reset_status},
BT_MESH_MODEL_OP_END,
};
@@ -1157,6 +1178,44 @@ done:
return err;
}
int bt_mesh_cfg_node_reset(uint16_t net_idx, uint16_t addr, bool *status)
{
struct os_mbuf *msg = BT_MESH_MODEL_BUF(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;
}
err = cli_prepare(status, OP_NODE_RESET_STATUS);
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);
cli_reset();
return err;
}
if (!status) {
cli_reset();
return 0;
}
return cli_wait();
}
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)
{
+29 -3
View File
@@ -609,11 +609,37 @@ struct shell_cmd_help cmd_uuid_help = {
static int cmd_reset(int argc, char *argv[])
{
bt_mesh_reset();
printk("Local node reset complete\n");
uint16_t addr;
if (argc < 2) {
return -EINVAL;
}
addr = strtoul(argv[1], NULL, 0);
if (addr == net.local) {
bt_mesh_reset();
printk("Local node reset complete");
} else {
int err;
bool reset = false;
err = bt_mesh_cfg_node_reset(net.net_idx, net.dst, &reset);
if (err) {
printk("Unable to send "
"Remote Node Reset (err %d)", err);
return 0;
}
printk("Remote node reset complete");
}
return 0;
}
struct shell_cmd_help cmd_reset_help = {
NULL, "<addr>", NULL
};
static uint8_t str2u8(const char *str)
{
if (isdigit(str[0])) {
@@ -3259,7 +3285,7 @@ static const struct shell_cmd mesh_commands[] = {
{
.sc_cmd = "reset",
.sc_cmd_func = cmd_reset,
.help = NULL,
.help = &cmd_reset_help,
},
{
.sc_cmd = "uuid",