linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, inga.stotland@intel.com
Subject: [PATCH BlueZ 2/2] mesh: Recognize SNBs in SecondsSinceLastHeard
Date: Fri, 20 Dec 2019 12:13:40 -0800	[thread overview]
Message-ID: <20191220201340.8039-3-brian.gix@intel.com> (raw)
In-Reply-To: <20191220201340.8039-1-brian.gix@intel.com>

Timestamp is taken on each OTA beacon reception, and considered in the
SecondsSinceLastHeard property.

---
 mesh/net-keys.c | 16 +++++++++++++---
 mesh/net-keys.h |  1 +
 mesh/net.c      | 15 +++++++++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/mesh/net-keys.c b/mesh/net-keys.c
index 6f1758fe3..683a924c4 100644
--- a/mesh/net-keys.c
+++ b/mesh/net-keys.c
@@ -410,7 +410,6 @@ static void snb_timeout(struct l_timeout *timeout, void *user_data)
 	}
 
 	interval = key->snb.observe_period / 2;
-	key->snb.ts = get_timestamp_secs();
 	key->snb.half_period = !key->snb.half_period;
 
 	if (key->beacon_enables)
@@ -425,8 +424,20 @@ void net_key_beacon_seen(uint32_t id)
 {
 	struct net_key *key = l_queue_find(keys, match_id, L_UINT_TO_PTR(id));
 
-	if (key)
+	if (key) {
 		key->snb.observed++;
+		key->snb.ts = get_timestamp_secs();
+	}
+}
+
+uint32_t net_key_beacon_last_seen(uint32_t id)
+{
+	struct net_key *key = l_queue_find(keys, match_id, L_UINT_TO_PTR(id));
+
+	if (key)
+		return key->snb.ts;
+
+	return 0;
 }
 
 void net_key_beacon_enable(uint32_t id)
@@ -451,7 +462,6 @@ void net_key_beacon_enable(uint32_t id)
 	rand_ms++;
 
 	/* Enable Periodic Beaconing on this key */
-	key->snb.ts = get_timestamp_secs();
 	key->snb.observe_period = BEACON_INTERVAL_MIN * 2;
 	key->snb.expected = 2;
 	key->snb.observed = 0;
diff --git a/mesh/net-keys.h b/mesh/net-keys.h
index 3c2c4d0da..9385e2c51 100644
--- a/mesh/net-keys.h
+++ b/mesh/net-keys.h
@@ -39,3 +39,4 @@ void net_key_beacon_seen(uint32_t id);
 void net_key_beacon_enable(uint32_t id);
 bool net_key_beacon_refresh(uint32_t id, uint32_t iv_index, bool kr, bool ivu);
 void net_key_beacon_disable(uint32_t id);
+uint32_t net_key_beacon_last_seen(uint32_t id);
diff --git a/mesh/net.c b/mesh/net.c
index 5aeeab188..23565c11d 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -3662,7 +3662,22 @@ void mesh_net_set_prov(struct mesh_net *net, struct mesh_prov *prov)
 	net->prov = prov;
 }
 
+static void refresh_instant(void *a, void *b)
+{
+	struct mesh_subnet *subnet = a;
+	struct mesh_net *net = b;
+	uint32_t instant = net_key_beacon_last_seen(subnet->net_key_tx);
+
+	if (net->instant < instant)
+		net->instant = instant;
+}
+
 uint32_t mesh_net_get_instant(struct mesh_net *net)
 {
+	if (!net)
+		return 0;
+
+	l_queue_foreach(net->subnets, refresh_instant, net);
+
 	return net->instant;
 }
-- 
2.21.0


  parent reply	other threads:[~2019-12-20 20:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 20:13 [PATCH BlueZ 0/2] mesh: Fix some SNB details Brian Gix
2019-12-20 20:13 ` [PATCH BlueZ 1/2] mesh: Deliver newly composed SNBs to local nodes Brian Gix
2019-12-20 20:13 ` Brian Gix [this message]
2019-12-24 19:03 ` [PATCH BlueZ 0/2] mesh: Fix some SNB details Gix, Brian

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=20191220201340.8039-3-brian.gix@intel.com \
    --to=brian.gix@intel.com \
    --cc=inga.stotland@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).