diff --git a/mesh/net-keys.c b/mesh/net-keys.c
index 6f1758f..683a924 100644
--- a/mesh/net-keys.c
+++ b/mesh/net-keys.c
}
interval = key->snb.observe_period / 2;
- key->snb.ts = get_timestamp_secs();
key->snb.half_period = !key->snb.half_period;
if (key->beacon_enables)
{
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)
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 3c2c4d0..9385e2c 100644
--- a/mesh/net-keys.h
+++ b/mesh/net-keys.h
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 5aeeab1..23565c1 100644
--- a/mesh/net.c
+++ b/mesh/net.c
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;
}