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 1/4] mesh: Correct u32 to u8 log transformation
Date: Mon, 26 Sep 2022 15:01:07 +0200	[thread overview]
Message-ID: <20220926130110.2146-2-isak.westin@loytec.com> (raw)
In-Reply-To: <20220926130110.2146-1-isak.westin@loytec.com>

Fixed the log transformation to correctly follow the value mapping
defined in the mesh profile (section 4.1.2).
---
 mesh/cfgmod-server.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 9bc2f1c97..33796d05a 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -455,14 +455,14 @@ done:
 static uint8_t uint32_to_log(uint32_t value)
 {
 	uint32_t val = 1;
-	uint8_t ret = 1;
+	uint8_t ret = 0;
 
 	if (!value)
 		return 0;
 	else if (value > 0x10000)
 		return 0xff;
 
-	while (val < value) {
+	while (val <= value) {
 		val <<= 1;
 		ret++;
 	}
@@ -495,7 +495,7 @@ static uint16_t hb_subscription_get(struct mesh_node *node, int status)
 	l_put_le16(sub->dst, msg + n);
 	n += 2;
 	msg[n++] = uint32_to_log(time_now.tv_sec);
-	msg[n++] = uint32_to_log(sub->count);
+	msg[n++] = sub->count != 0xffff ? uint32_to_log(sub->count) : 0xff;
 	msg[n++] = sub->count ? sub->min_hops : 0;
 	msg[n++] = sub->max_hops;
 
@@ -538,7 +538,7 @@ static uint16_t hb_publication_get(struct mesh_node *node, int status)
 	msg[n++] = status;
 	l_put_le16(pub->dst, msg + n);
 	n += 2;
-	msg[n++] = uint32_to_log(pub->count);
+	msg[n++] = pub->count != 0xffff ? uint32_to_log(pub->count) : 0xff;
 	msg[n++] = uint32_to_log(pub->period);
 	msg[n++] = pub->ttl;
 	l_put_le16(pub->features, msg + n);
-- 
2.20.1






  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 ` Isak Westin [this message]
2022-09-26 15:54   ` 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 ` [PATCH BlueZ 4/4] mesh: Clear HB sub status field if disabled Isak Westin
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-2-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.