Bluetooth: Mesh: Adds three Config Client API.

Those APIs are used for deleting appkey, unbinding an application
from SIG model, unbinding an application from vendor model on the
target node, with matching shell command.

Signed-off-by: YanBiao Hao <haoyanbiao@126.com>
This commit is contained in:
YanBiao Hao 2020-09-02 20:45:07 +08:00 committed by Carles Cufí
commit e877ee6088
4 changed files with 254 additions and 0 deletions

View file

@ -413,6 +413,15 @@ The Configuration Client uses the general messages parameters set by ``mesh dst`
* ``NetKeyIndex``: Network key indexes to get a list of application key indexes from.
``mesh app-key-del <NetKeyIndex> <AppKeyIndex>``
------------------------------------------------
Delete an application key from the target node.
* ``NetKeyIndex``: The network key index the application key is bound to.
* ``AppKeyIndex``: The application key index to delete.
``mesh mod-app-bind <addr> <AppIndex> <Model ID> [Company ID]``
---------------------------------------------------------------
@ -424,6 +433,18 @@ The Configuration Client uses the general messages parameters set by ``mesh dst`
* ``Company ID``: If present, determines the Company ID of the model. If omitted, the model is a Bluetooth SIG defined model.
``mesh mod-app-unbind <addr> <AppIndex> <Model ID> [Company ID]``
-----------------------------------------------------------------
Unbind an application key from a model.
* ``addr``: Address of the element the model is on.
* ``AppIndex``: The application key to unbind from the model.
* ``Model ID``: The model ID of the model to unbind the key from.
* ``Company ID``: If present, determines the Company ID of the model. If omitted, the model is a Bluetooth SIG defined model.
``mesh mod-app-get <elem addr> <Model ID> [Company ID]``
--------------------------------------------------------

View file

@ -273,6 +273,20 @@ int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
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);
/** @brief Delete an application key from the target node.
*
* @param net_idx Network index to encrypt with.
* @param addr Target node address.
* @param key_net_idx Network key index the application key belongs to.
* @param key_app_idx Application key index.
* @param status Status response parameter.
*
* @return 0 on success, or (negative) error code on failure.
*/
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);
/** @brief Bind an application to a SIG model on the target node.
*
* @param net_idx Network index to encrypt with.
@ -287,6 +301,21 @@ int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
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);
/** @brief Unbind an application from 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_app_idx Application index to unbind.
* @param mod_id Model ID.
* @param status Status response parameter.
*
* @return 0 on success, or (negative) error code on failure.
*/
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);
/** @brief Bind an application to a vendor model on the target node.
*
* @param net_idx Network index to encrypt with.
@ -303,6 +332,22 @@ int bt_mesh_cfg_mod_app_bind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_
uint16_t mod_app_idx, uint16_t mod_id, uint16_t cid,
uint8_t *status);
/** @brief Unbind an application from 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_app_idx Application index to unbind.
* @param mod_id Model ID.
* @param cid Company ID of the model.
* @param status Status response parameter.
*
* @return 0 on success, or (negative) error code on failure.
*/
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);
/** @brief Get a list of all applications bound to a SIG model on the target
* node.
*

View file

@ -1161,6 +1161,46 @@ int bt_mesh_cfg_app_key_get(uint16_t net_idx, uint16_t addr, uint16_t key_net_id
return cli_wait();
}
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)
{
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;
err = cli_prepare(&param, OP_APP_KEY_STATUS);
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);
cli_reset();
return err;
}
if (!status) {
cli_reset();
return 0;
}
return cli_wait();
}
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)
@ -1230,6 +1270,76 @@ int bt_mesh_cfg_mod_app_bind_vnd(uint16_t net_idx, uint16_t addr, uint16_t elem_
status);
}
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)
{
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;
err = cli_prepare(&param, OP_MOD_APP_STATUS);
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);
cli_reset();
return err;
}
if (!status) {
cli_reset();
return 0;
}
return cli_wait();
}
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 mod_app_unbind(net_idx, addr, elem_addr, mod_app_idx, mod_id,
CID_NVAL, 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)
{
if (cid == CID_NVAL) {
return -EINVAL;
}
return mod_app_unbind(net_idx, addr, elem_addr, mod_app_idx,
mod_id, cid, status);
}
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,

View file

@ -1165,6 +1165,37 @@ static int cmd_app_key_get(const struct shell *shell, size_t argc, char *argv[])
return 0;
}
static int cmd_app_key_del(const struct shell *shell, size_t argc, char *argv[])
{
uint16_t key_net_idx, key_app_idx;
uint8_t status;
int err;
if (argc < 3) {
return -EINVAL;
}
key_net_idx = strtoul(argv[1], NULL, 0);
key_app_idx = strtoul(argv[2], NULL, 0);
err = bt_mesh_cfg_app_key_del(net.net_idx, net.dst, key_net_idx,
key_app_idx, &status);
if (err) {
shell_error(shell, "Unable to send App Key del(err %d)", err);
return 0;
}
if (status) {
shell_print(shell, "AppKeyDel failed with status 0x%02x",
status);
} else {
shell_print(shell, "AppKey deleted, NetKeyIndex 0x%04x "
"AppKeyIndex 0x%04x", key_net_idx, key_app_idx);
}
return 0;
}
static int cmd_mod_app_bind(const struct shell *shell, size_t argc,
char *argv[])
{
@ -1206,6 +1237,48 @@ static int cmd_mod_app_bind(const struct shell *shell, size_t argc,
return 0;
}
static int cmd_mod_app_unbind(const struct shell *shell, size_t argc,
char *argv[])
{
uint16_t elem_addr, mod_app_idx, mod_id, cid;
uint8_t status;
int err;
if (argc < 4) {
return -EINVAL;
}
elem_addr = strtoul(argv[1], NULL, 0);
mod_app_idx = strtoul(argv[2], NULL, 0);
mod_id = strtoul(argv[3], NULL, 0);
if (argc > 4) {
cid = strtoul(argv[4], NULL, 0);
err = bt_mesh_cfg_mod_app_unbind_vnd(net.net_idx, net.dst,
elem_addr, mod_app_idx,
mod_id, cid, &status);
} else {
err = bt_mesh_cfg_mod_app_unbind(net.net_idx, net.dst,
elem_addr, mod_app_idx, mod_id, &status);
}
if (err) {
shell_error(shell, "Unable to send Model App Unbind (err %d)",
err);
return 0;
}
if (status) {
shell_print(shell, "Model App Unbind failed with status 0x%02x",
status);
} else {
shell_print(shell, "AppKey successfully unbound");
}
return 0;
}
static int cmd_mod_app_get(const struct shell *shell, size_t argc,
char *argv[])
{
@ -2603,6 +2676,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(mesh_cmds,
0),
SHELL_CMD_ARG(app-key-add, NULL, "<NetKeyIndex> <AppKeyIndex> [val]",
cmd_app_key_add, 3, 1),
SHELL_CMD_ARG(app-key-del, NULL, "<NetKeyIndex> <AppKeyIndex>",
cmd_app_key_del, 3, 0),
SHELL_CMD_ARG(app-key-get, NULL, "<NetKeyIndex>", cmd_app_key_get, 2,
0),
SHELL_CMD_ARG(mod-app-bind, NULL,
@ -2611,6 +2686,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(mesh_cmds,
SHELL_CMD_ARG(mod-app-get, NULL,
"<elem addr> <Model ID> [Company ID]",
cmd_mod_app_get, 3, 1),
SHELL_CMD_ARG(mod-app-unbind, NULL,
"<addr> <AppIndex> <Model ID> [Company ID]",
cmd_mod_app_unbind, 4, 1),
SHELL_CMD_ARG(mod-pub, NULL, "<addr> <mod id> [cid] [<PubAddr> "
"<AppKeyIndex> <cred: off, on> <ttl> <period> <count> <interval>]",
cmd_mod_pub, 3, 1 + 7),