2017-10-17 13:58:29

by Steve Brown

[permalink] [raw]
Subject: [PATCH 0/2] mesh: Add heartbeat command to meshctl

From: Steve Brown <[email protected]>

Tested with zephyr/samples/bluetooth/mesh on a nrf52840-pca10056 board
Needs zephyr commits through db0ee4ea626f706248681868d801d4a578d182bb

Steve Brown (2):
mesh: Add heartbeat publish command and status display
mesh: Add heartbeat message display

mesh/config-client.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
mesh/net.c | 18 +++++++++++++++
2 files changed, 80 insertions(+)

--
2.11.0



2017-10-17 13:58:31

by Steve Brown

[permalink] [raw]
Subject: [PATCH 2/2] mesh: Add heartbeat message display

From: Steve Brown <[email protected]>

---

Not too sure where to put this until subscribe is fully implemented.
---
mesh/net.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/mesh/net.c b/mesh/net.c
index 96e82fe1c..9b349b954 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -1399,6 +1399,24 @@ static bool ctl_rxed(uint16_t net_idx, uint32_t iv_index,
uint8_t *trans, uint16_t len)
{
/* TODO: Handle control messages */
+
+ /* Per Mesh Profile 3.6.5.10 */
+ if (trans[0] == NET_OP_HEARTBEAT) {
+ uint16_t feat = get_be16(trans + 2);
+
+ rl_printf("HEARTBEAT src: %4.4x dst: %4.4x "
+ "TTL: %2.2x feat: %s%s%s%s\n",
+ src, dst, trans[1],
+ (feat & MESH_FEATURE_RELAY) ? "relay " : "",
+ (feat & MESH_FEATURE_PROXY) ? "proxy " : "",
+ (feat & MESH_FEATURE_FRIEND) ? "friend " : "",
+ (feat & MESH_FEATURE_LPN) ? "lpn" : "");
+ return true;
+ }
+
+ rl_printf("unrecognized control message src:%4.4x dst:%4.4x len:%d\n",
+ src, dst, len);
+ print_byte_array("msg: ", trans, len);
return false;
}

--
2.11.0


2017-10-17 13:58:30

by Steve Brown

[permalink] [raw]
Subject: [PATCH 1/2] mesh: Add heartbeat publish command and status display

From: Steve Brown <[email protected]>

Also display uninterpreted opcodes
---
mesh/config-client.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)

diff --git a/mesh/config-client.c b/mesh/config-client.c
index d80f784e6..90a5a9399 100644
--- a/mesh/config-client.c
+++ b/mesh/config-client.c
@@ -83,6 +83,8 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,

switch (opcode & ~OP_UNRELIABLE) {
default:
+ rl_printf("Unrecognized opcode: %8.8x\n", opcode);
+ print_byte_array("data: ", data, len);
return false;

case OP_DEV_COMP_STATUS:
@@ -219,6 +221,24 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data,
prov_db_node_set_model_pub(node, ele_idx, mod_id,
node_model_pub_get(node, ele_idx, mod_id));
break;
+
+ /* Per Mesh Profile 4.3.2.63 */
+ case OP_CONFIG_HEARTBEAT_PUB_STATUS:
+
+ rl_printf("\nSet heartbeat for node %4.4x status: %s\n", src,
+ data[0] == MESH_STATUS_SUCCESS ? "Success" :
+ mesh_status_str(data[0]));
+
+ if (data[0] != MESH_STATUS_SUCCESS)
+ return true;
+
+ rl_printf("Destination:\t%4.4x\n", get_le16(data + 1));
+ rl_printf("Count:\t\t%2.2x\n", data[3]);
+ rl_printf("Period:\t\t%2.2x\n", data[4]);
+ rl_printf("TTL:\t\t%2.2x\n", data[5]);
+ rl_printf("Features:\t%4.4x\n", get_le16(data + 6));
+ rl_printf("Net_Idx:\t%4.4x\n", get_le16(data + 8));
+ break;
}
return true;
}
@@ -570,6 +590,46 @@ static void cmd_set_pub(const char *args)
rl_printf("Failed to send \"SET MODEL PUBLICATION\"\n");
}

+static void cmd_set_hb(const char *args)
+{
+ uint16_t n;
+ uint8_t msg[32];
+ int parm_cnt;
+
+ if (IS_UNASSIGNED(target)) {
+ rl_printf("Destination not set\n");
+ return;
+ }
+
+ n = mesh_opcode_set(OP_CONFIG_HEARTBEAT_PUB_SET, msg);
+
+ parm_cnt = read_input_parameters(args);
+ if (parm_cnt != 5) {
+ rl_printf("Bad arguments: %s\n", args);
+ return;
+ }
+
+ /* Per Mesh Profile 4.3.2.62 */
+ /* Publish address */
+ put_le16(parms[0], msg + n);
+ n += 2;
+ /* Count Log */
+ msg[n++] = parms[1];
+ /* Period Log */
+ msg[n++] = parms[2];
+ /* Heartbeat TTL */
+ msg[n++] = DEFAULT_TTL;
+ /* Features */
+ put_le16(parms[3], msg + n);
+ n += 2;
+ /* NetKey Index */
+ put_le16(parms[4], msg + n);
+ n += 2;
+
+ if (!config_send(msg, n))
+ rl_printf("Failed to send \"SET HEARTBEAT PUBLICATION\"\n");
+}
+
static void cmd_default(uint32_t opcode)
{
uint16_t n;
@@ -620,6 +680,8 @@ static const struct menu_entry cfg_menu[] = {
{"set-pub", "<ele_addr> <pub_addr> <app_idx> "
"<period (step|res)> <model>",
cmd_set_pub, "Set publication"},
+ {"set-hb", "<pub_addr> <count> <period> <features> <net_idx>",
+ cmd_set_hb, "Set heartbeat"},
{"back", NULL, cmd_back,
"Back to main menu"},
{"help", NULL, cmd_help,
--
2.11.0