All of lore.kernel.org
 help / color / mirror / Atom feed
From: Isak Westin <isak.westin@loytec.com>
To: linux-bluetooth@vger.kernel.org
Cc: Isak Westin <isak.westin@loytec.com>
Subject: [PATCH BlueZ 4/4] mesh: Clear HB sub status field if disabled
Date: Mon, 26 Sep 2022 15:01:10 +0200	[thread overview]
Message-ID: <20220926130110.2146-5-isak.westin@loytec.com> (raw)
In-Reply-To: <20220926130110.2146-1-isak.westin@loytec.com>

When replying to a HB subscription get message, and the current state of
source or destination fields is zero (which means that HB subscription
is disabled), all fields in the status reply should be zero.
---
 mesh/cfgmod-server.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 55a2d896b..7044b670d 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -470,7 +470,7 @@ static uint8_t uint32_to_log(uint32_t value)
 	return ret;
 }
 
-static uint16_t hb_subscription_get(struct mesh_node *node, int status)
+static uint16_t hb_subscription_status(struct mesh_node *node, int status)
 {
 	struct mesh_net *net = node_get_net(node);
 	struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);
@@ -502,6 +502,28 @@ static uint16_t hb_subscription_get(struct mesh_node *node, int status)
 	return n;
 }
 
+static uint16_t hb_subscription_get(struct mesh_node *node, int status)
+{
+	struct mesh_net *net = node_get_net(node);
+	struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);
+
+	/*
+	 * MshPRFv1.0.1 section 4.4.1.2.16, Heartbeat Subscription state:
+	 * If this is a GET request and the source or destination is unassigned,
+	 * all fields shall be set to zero in the status reply.
+	 */
+	if (IS_UNASSIGNED(sub->src) || IS_UNASSIGNED(sub->dst)) {
+		uint16_t n;
+
+		n = mesh_model_opcode_set(OP_CONFIG_HEARTBEAT_SUB_STATUS, msg);
+		memset(msg + n, 0, 9);
+		n += 9;
+		return n;
+	}
+
+	return hb_subscription_status(node, status);
+}
+
 static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)
 {
 	uint16_t src, dst;
@@ -525,7 +547,7 @@ static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)
 
 	status = mesh_net_set_heartbeat_sub(net, src, dst, period_log);
 
-	return hb_subscription_get(node, status);
+	return hb_subscription_status(node, status);
 }
 
 static uint16_t hb_publication_get(struct mesh_node *node, int status)
-- 
2.20.1






  parent reply	other threads:[~2022-09-26 14:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 13:01 [PATCH BlueZ 0/4] Mesh: Fix heartbeat publication/subscription Isak Westin
2022-09-26 13:01 ` [PATCH BlueZ 1/4] mesh: Correct u32 to u8 log transformation Isak Westin
2022-09-26 15:54   ` Mesh: Fix heartbeat publication/subscription bluez.test.bot
2022-09-26 13:01 ` [PATCH BlueZ 2/4] mesh: Reply to HB pub set with same fields Isak Westin
2022-09-26 13:01 ` [PATCH BlueZ 3/4] mesh: Correct HB sub state updates Isak Westin
2022-09-26 13:01 ` Isak Westin [this message]
2022-09-26 20:20 ` [PATCH BlueZ 0/4] Mesh: Fix heartbeat publication/subscription patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220926130110.2146-5-isak.westin@loytec.com \
    --to=isak.westin@loytec.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.