Bluetooth: Mesh: Add cfg cli list getters

Adds config client getters for all list commands:
- mod_app_get
- mod_sub_get
- net_key_get
- app_key_get

Closes #24505.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
Trond Einar Snekvik 2020-04-22 10:14:12 +02:00 committed by Johan Hedberg
commit 86137c3a62
3 changed files with 650 additions and 5 deletions

View file

@ -211,6 +211,21 @@ int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx, int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
const u8_t net_key[16], u8_t *status); const u8_t net_key[16], u8_t *status);
/** @brief Get a list of the target node's network key indexes.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param keys Net key index list response parameter. Will be filled with
* all the returned network key indexes it can fill.
* @param key_cnt Net key index list length. Should be set to the
* capacity of the @c keys list when calling. Will return the
* number of returned network key indexes upon success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_net_key_get(u16_t net_idx, u16_t addr, u16_t *keys,
size_t *key_cnt);
/** @brief Add an application key to the target node. /** @brief Add an application key to the target node.
* *
* @param net_idx Network index to encrypt with. * @param net_idx Network index to encrypt with.
@ -226,6 +241,26 @@ int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
u16_t key_app_idx, const u8_t app_key[16], u16_t key_app_idx, const u8_t app_key[16],
u8_t *status); u8_t *status);
/** @brief Get a list of the target node's application key indexes for a
* specific network key.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param key_net_idx Network key index to request the app key indexes of.
* @param status Status response parameter.
* @param keys App key index list response parameter. Will be filled
* with all the returned application key indexes it can
* fill.
* @param key_cnt App key index list length. Should be set to the
* capacity of the @c keys list when calling. Will return
* the number of returned application key indexes upon
* success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_app_key_get(u16_t net_idx, u16_t addr, u16_t key_net_idx,
u8_t *status, u16_t *keys, size_t *key_cnt);
/** @brief Bind an application to a SIG model on the target node. /** @brief Bind an application to a SIG model on the target node.
* *
* @param net_idx Network index to encrypt with. * @param net_idx Network index to encrypt with.
@ -256,6 +291,48 @@ int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_app_idx, u16_t mod_id, u16_t cid, u16_t mod_app_idx, u16_t mod_id, u16_t cid,
u8_t *status); u8_t *status);
/** @brief Get a list of all applications bound to a SIG model on the target
* node.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param elem_addr Element address the model is in.
* @param mod_id Model ID.
* @param status Status response parameter.
* @param apps App index list response parameter. Will be filled with all
* the returned application key indexes it can fill.
* @param app_cnt App index list length. Should be set to the capacity of the
* @c apps list when calling. Will return the number of
* returned application key indexes upon success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_mod_app_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u8_t *status, u16_t *apps,
size_t *app_cnt);
/** @brief Get a list of all applications bound to a vendor model on the target
* node.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param elem_addr Element address the model is in.
* @param mod_id Model ID.
* @param cid Company ID of the model.
* @param status Status response parameter.
* @param apps App index list response parameter. Will be filled with all
* the returned application key indexes it can fill.
* @param app_cnt App index list length. Should be set to the capacity of the
* @c apps list when calling. Will return the number of
* returned application key indexes upon success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_mod_app_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u16_t cid, u8_t *status,
u16_t *apps, size_t *app_cnt);
/** @def BT_MESH_PUB_PERIOD_100MS /** @def BT_MESH_PUB_PERIOD_100MS
* *
* @brief Helper macro to encode model publication period in units of 100ms * @brief Helper macro to encode model publication period in units of 100ms
@ -591,6 +668,45 @@ int bt_mesh_cfg_mod_sub_va_overwrite_vnd(u16_t net_idx, u16_t addr,
u16_t mod_id, u16_t cid, u16_t mod_id, u16_t cid,
u16_t *virt_addr, u8_t *status); u16_t *virt_addr, u8_t *status);
/** @brief Get the subscription list of a SIG model on the target node.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param elem_addr Element address the model is in.
* @param mod_id Model ID.
* @param status Status response parameter.
* @param subs Subscription list response parameter. Will be filled with
* all the returned subscriptions it can fill.
* @param sub_cnt Subscription list element count. Should be set to the
* capacity of the @c subs list when calling. Will return the
* number of returned subscriptions upon success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_mod_sub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u8_t *status, u16_t *subs,
size_t *sub_cnt);
/** @brief Get the subscription list of a vendor model on the target node.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param elem_addr Element address the model is in.
* @param mod_id Model ID.
* @param cid Company ID of the model.
* @param status Status response parameter.
* @param subs Subscription list response parameter. Will be filled with
* all the returned subscriptions it can fill.
* @param sub_cnt Subscription list element count. Should be set to the
* capacity of the @c subs list when calling. Will return the
* number of returned subscriptions upon success.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_cfg_mod_sub_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u16_t cid, u8_t *status,
u16_t *subs, size_t *sub_cnt);
/** Heartbeat subscription configuration parameters. */ /** Heartbeat subscription configuration parameters. */
struct bt_mesh_cfg_hb_sub { struct bt_mesh_cfg_hb_sub {
/** Source address to receive Heartbeat messages from. */ /** Source address to receive Heartbeat messages from. */

View file

@ -180,6 +180,42 @@ static void net_key_status(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync); k_sem_give(&cli->op_sync);
} }
struct net_key_list_param {
u16_t *keys;
size_t *key_cnt;
};
static void net_key_list(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
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));
if (cli->op_pending != OP_NET_KEY_LIST) {
BT_WARN("Unexpected Net Key List message");
return;
}
param = cli->op_param;
for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) {
key_idx_unpack(buf, &param->keys[i], &param->keys[i + 1]);
}
if (i < *param->key_cnt && buf->len >= 2) {
param->keys[i++] = net_buf_simple_pull_le16(buf) & 0xfff;
}
*param->key_cnt = i;
k_sem_give(&cli->op_sync);
}
struct app_key_param { struct app_key_param {
u8_t *status; u8_t *status;
u16_t net_idx; u16_t net_idx;
@ -219,6 +255,56 @@ static void app_key_status(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync); k_sem_give(&cli->op_sync);
} }
struct app_key_list_param {
u16_t net_idx;
u8_t *status;
u16_t *keys;
size_t *key_cnt;
};
static void app_key_list(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
struct app_key_list_param *param;
u16_t net_idx;
u8_t status;
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));
if (cli->op_pending != OP_APP_KEY_LIST) {
BT_WARN("Unexpected App Key List message");
return;
}
status = net_buf_simple_pull_u8(buf);
net_idx = net_buf_simple_pull_le16(buf) & 0xfff;
param = cli->op_param;
if (param->net_idx != net_idx) {
BT_WARN("App Key List Net Key index did not match");
return;
}
for (i = 0; i < *param->key_cnt && buf->len >= 3; i += 2) {
key_idx_unpack(buf, &param->keys[i], &param->keys[i + 1]);
}
if (i < *param->key_cnt && buf->len >= 2) {
param->keys[i++] = net_buf_simple_pull_le16(buf) & 0xfff;
}
*param->key_cnt = i;
if (param->status) {
*param->status = status;
}
k_sem_give(&cli->op_sync);
}
struct mod_app_param { struct mod_app_param {
u8_t *status; u8_t *status;
u16_t elem_addr; u16_t elem_addr;
@ -271,6 +357,87 @@ static void mod_app_status(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync); k_sem_give(&cli->op_sync);
} }
struct mod_member_list_param {
u8_t *status;
u16_t elem_addr;
u16_t mod_id;
u16_t cid;
u16_t *members;
size_t *member_cnt;
};
static void mod_member_list_handle(struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool vnd)
{
struct mod_member_list_param *param;
u16_t elem_addr, mod_id, cid;
u8_t status;
int i;
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);
param = cli->op_param;
if (param->elem_addr != elem_addr || param->mod_id != mod_id ||
(vnd && param->cid != cid)) {
BT_WARN("Model Member List parameters did not match");
return;
}
if (buf->len % 2) {
BT_WARN("Model Member List invalid length");
return;
}
for (i = 0; i < *param->member_cnt && buf->len; i++) {
param->members[i] = net_buf_simple_pull_le16(buf);
}
*param->member_cnt = i;
if (param->status) {
*param->status = status;
}
k_sem_give(&cli->op_sync);
}
static void mod_app_list(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
bt_hex(buf->data, buf->len));
if (cli->op_pending != OP_SIG_MOD_APP_LIST) {
BT_WARN("Unexpected Model App List message");
return;
}
mod_member_list_handle(ctx, buf, false);
}
static void mod_app_list_vnd(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
bt_hex(buf->data, buf->len));
if (cli->op_pending != OP_VND_MOD_APP_LIST) {
BT_WARN("Unexpected Model App List Vendor message");
return;
}
mod_member_list_handle(ctx, buf, true);
}
struct mod_pub_param { struct mod_pub_param {
u16_t mod_id; u16_t mod_id;
u16_t cid; u16_t cid;
@ -403,6 +570,38 @@ static void mod_sub_status(struct bt_mesh_model *model,
k_sem_give(&cli->op_sync); k_sem_give(&cli->op_sync);
} }
static void mod_sub_list(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
bt_hex(buf->data, buf->len));
if (cli->op_pending != OP_MOD_SUB_LIST) {
BT_WARN("Unexpected Model Subscription List message");
return;
}
mod_member_list_handle(ctx, buf, false);
}
static void mod_sub_list_vnd(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
bt_hex(buf->data, buf->len));
if (cli->op_pending != OP_MOD_SUB_LIST_VND) {
BT_WARN("Unexpected Model Subscription List Vendor message");
return;
}
mod_member_list_handle(ctx, buf, true);
}
struct hb_sub_param { struct hb_sub_param {
u8_t *status; u8_t *status;
struct bt_mesh_cfg_hb_sub *sub; struct bt_mesh_cfg_hb_sub *sub;
@ -481,10 +680,16 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
{ OP_GATT_PROXY_STATUS, 1, gatt_proxy_status }, { OP_GATT_PROXY_STATUS, 1, gatt_proxy_status },
{ OP_RELAY_STATUS, 2, relay_status }, { OP_RELAY_STATUS, 2, relay_status },
{ OP_NET_KEY_STATUS, 3, net_key_status }, { OP_NET_KEY_STATUS, 3, net_key_status },
{ OP_NET_KEY_LIST, 0, net_key_list },
{ OP_APP_KEY_STATUS, 4, app_key_status }, { OP_APP_KEY_STATUS, 4, app_key_status },
{ OP_APP_KEY_LIST, 3, app_key_list },
{ OP_MOD_APP_STATUS, 7, mod_app_status }, { OP_MOD_APP_STATUS, 7, mod_app_status },
{ OP_SIG_MOD_APP_LIST, 5, mod_app_list},
{ OP_VND_MOD_APP_LIST, 7, mod_app_list_vnd},
{ OP_MOD_PUB_STATUS, 12, mod_pub_status }, { OP_MOD_PUB_STATUS, 12, mod_pub_status },
{ OP_MOD_SUB_STATUS, 7, mod_sub_status }, { OP_MOD_SUB_STATUS, 7, mod_sub_status },
{ OP_MOD_SUB_LIST, 5, mod_sub_list},
{ OP_MOD_SUB_LIST_VND, 7, mod_sub_list_vnd},
{ OP_HEARTBEAT_SUB_STATUS, 9, hb_sub_status }, { OP_HEARTBEAT_SUB_STATUS, 9, hb_sub_status },
{ OP_HEARTBEAT_PUB_STATUS, 10, hb_pub_status }, { OP_HEARTBEAT_PUB_STATUS, 10, hb_pub_status },
BT_MESH_MODEL_OP_END, BT_MESH_MODEL_OP_END,
@ -805,6 +1010,39 @@ int bt_mesh_cfg_net_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
return cli_wait(); return cli_wait();
} }
int bt_mesh_cfg_net_key_get(u16_t net_idx, u16_t addr, u16_t *keys,
size_t *key_cnt)
{
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;
err = cli_prepare(&param, OP_NET_KEY_LIST);
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);
cli_reset();
return err;
}
return cli_wait();
}
int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx, int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
u16_t key_app_idx, const u8_t app_key[16], u16_t key_app_idx, const u8_t app_key[16],
u8_t *status) u8_t *status)
@ -847,6 +1085,42 @@ int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
return cli_wait(); return cli_wait();
} }
int bt_mesh_cfg_app_key_get(u16_t net_idx, u16_t addr, u16_t key_net_idx,
u8_t *status, u16_t *keys, size_t *key_cnt)
{
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;
err = cli_prepare(&param, OP_APP_KEY_LIST);
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);
cli_reset();
return err;
}
return cli_wait();
}
static int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr, static int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_app_idx, u16_t mod_id, u16_t cid, u16_t mod_app_idx, u16_t mod_id, u16_t cid,
u8_t *status) u8_t *status)
@ -916,6 +1190,78 @@ int bt_mesh_cfg_mod_app_bind_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
status); status);
} }
static int mod_member_list_get(u32_t op, u32_t expect_op, u16_t net_idx,
u16_t addr, u16_t elem_addr, u16_t mod_id,
u16_t cid, u8_t *status, u16_t *apps,
size_t *app_cnt)
{
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;
err = cli_prepare(&param, expect_op);
if (err) {
return err;
}
BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x",
net_idx, addr, elem_addr);
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);
cli_reset();
return err;
}
return cli_wait();
}
int bt_mesh_cfg_mod_app_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u8_t *status, u16_t *apps,
size_t *app_cnt)
{
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);
}
int bt_mesh_cfg_mod_app_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u16_t cid, u8_t *status,
u16_t *apps, size_t *app_cnt)
{
if (cid == CID_NVAL) {
return -EINVAL;
}
return mod_member_list_get(OP_VND_MOD_APP_GET, OP_VND_MOD_APP_LIST,
net_idx, addr, elem_addr, mod_id, CID_NVAL,
status, apps, app_cnt);
}
static int mod_sub(u32_t op, u16_t net_idx, u16_t addr, u16_t elem_addr, static int mod_sub(u32_t op, u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t sub_addr, u16_t mod_id, u16_t cid, u8_t *status) u16_t sub_addr, u16_t mod_id, u16_t cid, u8_t *status)
{ {
@ -957,11 +1303,6 @@ static int mod_sub(u32_t op, u16_t net_idx, u16_t addr, u16_t elem_addr,
return err; return err;
} }
if (!status) {
cli_reset();
return 0;
}
return cli_wait(); return cli_wait();
} }
@ -1138,6 +1479,28 @@ int bt_mesh_cfg_mod_sub_va_overwrite_vnd(u16_t net_idx, u16_t addr,
label, mod_id, cid, virt_addr, status); label, mod_id, cid, virt_addr, status);
} }
int bt_mesh_cfg_mod_sub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u8_t *status, u16_t *subs,
size_t *sub_cnt)
{
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);
}
int bt_mesh_cfg_mod_sub_get_vnd(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u16_t cid, u8_t *status,
u16_t *subs, size_t *sub_cnt)
{
if (cid == CID_NVAL) {
return -EINVAL;
}
return mod_member_list_get(OP_MOD_SUB_GET_VND, OP_MOD_SUB_LIST_VND,
net_idx, addr, elem_addr, mod_id, CID_NVAL,
status, subs, sub_cnt);
}
static int mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr, static int mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
u16_t mod_id, u16_t cid, u16_t mod_id, u16_t cid,
struct bt_mesh_cfg_mod_pub *pub, u8_t *status) struct bt_mesh_cfg_mod_pub *pub, u8_t *status)

View file

@ -1013,6 +1013,28 @@ static int cmd_net_key_add(const struct shell *shell, size_t argc, char *argv[])
return 0; return 0;
} }
static int cmd_net_key_get(const struct shell *shell, size_t argc, char *argv[])
{
u16_t keys[16];
size_t cnt;
int err, i;
cnt = ARRAY_SIZE(keys);
err = bt_mesh_cfg_net_key_get(net.net_idx, net.dst, keys, &cnt);
if (err) {
shell_print(shell, "Unable to send NetKeyGet (err %d)", err);
return 0;
}
shell_print(shell, "NetKeys known by 0x%04x:", net.dst);
for (i = 0; i < cnt; i++) {
shell_print(shell, "\t0x%03x", keys[i]);
}
return 0;
}
static int cmd_app_key_add(const struct shell *shell, size_t argc, char *argv[]) static int cmd_app_key_add(const struct shell *shell, size_t argc, char *argv[])
{ {
u8_t key_val[16]; u8_t key_val[16];
@ -1084,6 +1106,40 @@ static int cmd_app_key_add(const struct shell *shell, size_t argc, char *argv[])
return 0; return 0;
} }
static int cmd_app_key_get(const struct shell *shell, size_t argc, char *argv[])
{
u16_t net_idx;
u16_t keys[16];
size_t cnt;
u8_t status;
int err, i;
net_idx = strtoul(argv[1], NULL, 0);
cnt = ARRAY_SIZE(keys);
err = bt_mesh_cfg_app_key_get(net.net_idx, net.dst, net_idx, &status,
keys, &cnt);
if (err) {
shell_print(shell, "Unable to send AppKeyGet (err %d)", err);
return 0;
}
if (status) {
shell_print(shell, "AppKeyGet failed with status 0x%02x",
status);
return 0;
}
shell_print(shell,
"AppKeys for NetKey 0x%03x known by 0x%04x:", net_idx,
net.dst);
for (i = 0; i < cnt; i++) {
shell_print(shell, "\t0x%03x", keys[i]);
}
return 0;
}
static int cmd_mod_app_bind(const struct shell *shell, size_t argc, static int cmd_mod_app_bind(const struct shell *shell, size_t argc,
char *argv[]) char *argv[])
{ {
@ -1125,6 +1181,56 @@ static int cmd_mod_app_bind(const struct shell *shell, size_t argc,
return 0; return 0;
} }
static int cmd_mod_app_get(const struct shell *shell, size_t argc,
char *argv[])
{
u16_t elem_addr, mod_id, cid;
u16_t apps[16];
u8_t status;
size_t cnt;
int err, i;
elem_addr = strtoul(argv[1], NULL, 0);
mod_id = strtoul(argv[2], NULL, 0);
cnt = ARRAY_SIZE(apps);
if (argc > 3) {
cid = strtoul(argv[3], NULL, 0);
err = bt_mesh_cfg_mod_app_get_vnd(net.net_idx, net.dst,
elem_addr, mod_id, cid,
&status, apps, &cnt);
} else {
err = bt_mesh_cfg_mod_app_get(net.net_idx, net.dst, elem_addr,
mod_id, &status, apps, &cnt);
}
if (err) {
shell_error(shell, "Unable to send Model App Get (err %d)",
err);
return 0;
}
if (status) {
shell_print(shell, "Model App Get failed with status 0x%02x",
status);
} else {
shell_print(
shell,
"Apps bound to Element 0x%04x, Model 0x%04x %s:",
elem_addr, mod_id, argc > 3 ? argv[3] : "(SIG)");
if (!cnt) {
shell_print(shell, "\tNone.");
}
for (i = 0; i < cnt; i++) {
shell_print(shell, "\t0x%04x", apps[i]);
}
}
return 0;
}
static int cmd_mod_sub_add(const struct shell *shell, size_t argc, char *argv[]) static int cmd_mod_sub_add(const struct shell *shell, size_t argc, char *argv[])
{ {
u16_t elem_addr, sub_addr, mod_id, cid; u16_t elem_addr, sub_addr, mod_id, cid;
@ -1301,6 +1407,57 @@ static int cmd_mod_sub_del_va(const struct shell *shell, size_t argc,
return 0; return 0;
} }
static int cmd_mod_sub_get(const struct shell *shell, size_t argc,
char *argv[])
{
u16_t elem_addr, mod_id, cid;
u16_t subs[16];
u8_t status;
size_t cnt;
int err, i;
elem_addr = strtoul(argv[1], NULL, 0);
mod_id = strtoul(argv[2], NULL, 0);
cnt = ARRAY_SIZE(subs);
if (argc > 3) {
cid = strtoul(argv[3], NULL, 0);
err = bt_mesh_cfg_mod_sub_get_vnd(net.net_idx, net.dst,
elem_addr, mod_id, cid,
&status, subs, &cnt);
} else {
err = bt_mesh_cfg_mod_sub_get(net.net_idx, net.dst, elem_addr,
mod_id, &status, subs, &cnt);
}
if (err) {
shell_error(shell, "Unable to send Model Subscription Get "
"(err %d)", err);
return 0;
}
if (status) {
shell_print(shell, "Model Subscription Get failed with "
"status 0x%02x", status);
} else {
shell_print(
shell,
"Model Subscriptions for Element 0x%04x, "
"Model 0x%04x %s:",
elem_addr, mod_id, argc > 3 ? argv[3] : "(SIG)");
if (!cnt) {
shell_print(shell, "\tNone.");
}
for (i = 0; i < cnt; i++) {
shell_print(shell, "\t0x%04x", subs[i]);
}
}
return 0;
}
static int mod_pub_get(const struct shell *shell, u16_t addr, u16_t mod_id, static int mod_pub_get(const struct shell *shell, u16_t addr, u16_t mod_id,
u16_t cid) u16_t cid)
{ {
@ -2412,11 +2569,17 @@ SHELL_STATIC_SUBCMD_SET_CREATE(mesh_cmds,
1, 3), 1, 3),
SHELL_CMD_ARG(net-key-add, NULL, "<NetKeyIndex> [val]", cmd_net_key_add, SHELL_CMD_ARG(net-key-add, NULL, "<NetKeyIndex> [val]", cmd_net_key_add,
2, 1), 2, 1),
SHELL_CMD_ARG(net-key-get, NULL, NULL, cmd_net_key_get, 1, 0),
SHELL_CMD_ARG(app-key-add, NULL, "<NetKeyIndex> <AppKeyIndex> [val]", SHELL_CMD_ARG(app-key-add, NULL, "<NetKeyIndex> <AppKeyIndex> [val]",
cmd_app_key_add, 3, 1), cmd_app_key_add, 3, 1),
SHELL_CMD_ARG(app-key-get, NULL, "<NetKeyIndex>", cmd_app_key_get, 2,
0),
SHELL_CMD_ARG(mod-app-bind, NULL, SHELL_CMD_ARG(mod-app-bind, NULL,
"<addr> <AppIndex> <Model ID> [Company ID]", "<addr> <AppIndex> <Model ID> [Company ID]",
cmd_mod_app_bind, 4, 1), cmd_mod_app_bind, 4, 1),
SHELL_CMD_ARG(mod-app-get, NULL,
"<elem addr> <Model ID> [Company ID]",
cmd_mod_app_get, 3, 1),
SHELL_CMD_ARG(mod-pub, NULL, "<addr> <mod id> [cid] [<PubAddr> " SHELL_CMD_ARG(mod-pub, NULL, "<addr> <mod id> [cid] [<PubAddr> "
"<AppKeyIndex> <cred> <ttl> <period> <count> <interval>]", "<AppKeyIndex> <cred> <ttl> <period> <count> <interval>]",
cmd_mod_pub, 3, 1 + 7), cmd_mod_pub, 3, 1 + 7),
@ -2432,6 +2595,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(mesh_cmds,
SHELL_CMD_ARG(mod-sub-del-va, NULL, SHELL_CMD_ARG(mod-sub-del-va, NULL,
"<elem addr> <Label UUID> <Model ID> [Company ID]", "<elem addr> <Label UUID> <Model ID> [Company ID]",
cmd_mod_sub_del_va, 4, 1), cmd_mod_sub_del_va, 4, 1),
SHELL_CMD_ARG(mod-sub-get, NULL,
"<elem addr> <Model ID> [Company ID]",
cmd_mod_sub_get, 3, 1),
SHELL_CMD_ARG(hb-sub, NULL, "[<src> <dst> <period>]", cmd_hb_sub, 1, 3), SHELL_CMD_ARG(hb-sub, NULL, "[<src> <dst> <period>]", cmd_hb_sub, 1, 3),
SHELL_CMD_ARG(hb-pub, NULL, SHELL_CMD_ARG(hb-pub, NULL,
"[<dst> <count> <period> <ttl> <features> <NetKeyIndex>]", "[<dst> <count> <period> <ttl> <features> <NetKeyIndex>]",