Bluetooth: Mesh: shell: Add mod-pub command
Add a command for getting and setting the model publication. We also
have to adjust the app's configuration, since both the Model
Publication Set and Status messages are segmented messages, meaning we
need two TX and RX segment contexts.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
diff --git a/subsys/bluetooth/host/mesh/shell.c b/subsys/bluetooth/host/mesh/shell.c
index 7993b83..2c47c03 100644
--- a/subsys/bluetooth/host/mesh/shell.c
+++ b/subsys/bluetooth/host/mesh/shell.c
@@ -17,6 +17,8 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/mesh.h>
+#define CID_NVAL 0xffff
+
/* Default net, app & dev key values, unless otherwise specified */
static const u8_t default_key[16] = {
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
@@ -674,6 +676,128 @@
return 0;
}
+static int mod_pub_get(u16_t addr, u16_t mod_id, u16_t cid)
+{
+ struct bt_mesh_cfg_mod_pub pub;
+ u8_t status;
+ int err;
+
+ if (cid == CID_NVAL) {
+ err = bt_mesh_cfg_mod_pub_get(net.net_idx, net.dst, addr,
+ mod_id, &pub, &status);
+ } else {
+ err = bt_mesh_cfg_mod_pub_get_vnd(net.net_idx, net.dst, addr,
+ mod_id, cid, &pub, &status);
+ }
+
+ if (err) {
+ printk("Model Publication Get failed (err %d)\n", err);
+ return 0;
+ }
+
+ if (status) {
+ printk("Model Publication Get failed (status 0x%02x)\n",
+ status);
+ return 0;
+ }
+
+ printk("Model Publication for Element 0x%04x, Model 0x%04x:\n"
+ "\tPublish Address: 0x%04x\n"
+ "\tAppKeyIndex: 0x%04x\n"
+ "\tCredential Flag: %u\n"
+ "\tPublishTTL: %u\n"
+ "\tPublishPeriod: 0x%02x\n"
+ "\tPublishRetransmitCount: %u\n"
+ "\tPublishRetransmitIntervalSteps: %u\n",
+ addr, mod_id, pub.addr, pub.app_idx, pub.cred_flag, pub.ttl,
+ pub.period, BT_MESH_TRANSMIT_COUNT(pub.transmit),
+ BT_MESH_TRANSMIT_INT(pub.transmit));
+
+ return 0;
+}
+
+static int mod_pub_set(u16_t addr, u16_t mod_id, u16_t cid, char *argv[])
+{
+ struct bt_mesh_cfg_mod_pub pub;
+ u8_t status, count, interval;
+ int err;
+
+ pub.addr = strtoul(argv[0], NULL, 0);
+ pub.app_idx = strtoul(argv[1], NULL, 0);
+ pub.cred_flag = str2bool(argv[2]);
+ pub.ttl = strtoul(argv[3], NULL, 0);
+ pub.period = strtoul(argv[4], NULL, 0);
+
+ count = strtoul(argv[5], NULL, 0);
+ if (count > 7) {
+ printk("Invalid retransmit count\n");
+ return -EINVAL;
+ }
+
+ interval = strtoul(argv[6], NULL, 0);
+ if (interval > 31) {
+ printk("Invalid retransmit interval\n");
+ return -EINVAL;
+ }
+
+ pub.transmit = BT_MESH_TRANSMIT(count, interval);
+
+ if (cid == CID_NVAL) {
+ err = bt_mesh_cfg_mod_pub_set(net.net_idx, net.dst, addr,
+ mod_id, &pub, &status);
+ } else {
+ err = bt_mesh_cfg_mod_pub_set_vnd(net.net_idx, net.dst, addr,
+ mod_id, cid, &pub, &status);
+ }
+
+ if (err) {
+ printk("Model Publication Set failed (err %d)\n", err);
+ return 0;
+ }
+
+ if (status) {
+ printk("Model Publication Set failed (status 0x%02x)\n",
+ status);
+ } else {
+ printk("Model Publication successfully set\n");
+ }
+
+ return 0;
+}
+
+static int cmd_mod_pub(int argc, char *argv[])
+{
+ u16_t addr, mod_id, cid;
+
+ if (argc < 3) {
+ return -EINVAL;
+ }
+
+ addr = strtoul(argv[1], NULL, 0);
+ mod_id = strtoul(argv[2], NULL, 0);
+
+ argc -= 3;
+ argv += 3;
+
+ if (argc == 1 || argc == 8) {
+ cid = strtoul(argv[0], NULL, 0);
+ argc--;
+ argv++;
+ } else {
+ cid = CID_NVAL;
+ }
+
+ if (argc > 0) {
+ if (argc < 7) {
+ return -EINVAL;
+ }
+
+ return mod_pub_set(addr, mod_id, cid, argv);
+ } else {
+ return mod_pub_get(addr, mod_id, cid);
+ }
+}
+
static int hb_sub_get(int argc, char *argv[])
{
u8_t status, period, count, min, max;
@@ -949,6 +1073,8 @@
{ "app-key-add", cmd_app_key_add, "<NetKeyIndex> <AppKeyIndex> <val>" },
{ "mod-app-bind", cmd_mod_app_bind,
"<addr> <AppIndex> <Model ID> [Company ID]" },
+ { "mod-pub", cmd_mod_pub, "<addr> <mod id> [cid] [<PubAddr> "
+ "<AppKeyIndex> <cred> <ttl> <period> <count> <interval>]" },
{ "mod-sub-add", cmd_mod_sub_add,
"<elem addr> <sub addr> <Model ID> [Company ID]" },
{ "hb-sub", cmd_hb_sub, "[<src> <dst> <period>]" },
diff --git a/tests/bluetooth/shell/prj.conf b/tests/bluetooth/shell/prj.conf
index 817b857..753b316 100644
--- a/tests/bluetooth/shell/prj.conf
+++ b/tests/bluetooth/shell/prj.conf
@@ -32,6 +32,8 @@
CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16
CONFIG_BT_MESH_ADV_BUF_COUNT=20
CONFIG_BT_MESH_CFG_CLI=y
+CONFIG_BT_MESH_TX_SEG_MSG_COUNT=2
+CONFIG_BT_MESH_RX_SEG_MSG_COUNT=2
CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_PB_ADV=y