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