* [PATCH BlueZ 0/2] mesh: Fix some SNB details
@ 2019-12-20 20:13 Brian Gix
2019-12-20 20:13 ` [PATCH BlueZ 1/2] mesh: Deliver newly composed SNBs to local nodes Brian Gix
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Brian Gix @ 2019-12-20 20:13 UTC (permalink / raw)
To: linux-bluetooth; +Cc: brian.gix, inga.stotland
This fixes two minor flaws with Secure Net Beacons:
1. When a local node's SNB changes, all local nodes should be made aware
of the change a the same time we start sending out that beacon.
2. The second that a remote beacon is "seen" needs to be recorded so
that the SecondsSinceLastHeard property can be correctly updated.
Brian Gix (2):
mesh: Deliver newly composed SNBs to local nodes
mesh: Recognize SNBs in SecondsSinceLastHeard property
mesh/net-keys.c | 19 ++++++++++++++++---
mesh/net-keys.h | 1 +
mesh/net.c | 28 ++++++++++++++++++++++++++++
mesh/net.h | 1 +
4 files changed, 46 insertions(+), 3 deletions(-)
--
2.21.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH BlueZ 1/2] mesh: Deliver newly composed SNBs to local nodes
2019-12-20 20:13 [PATCH BlueZ 0/2] mesh: Fix some SNB details Brian Gix
@ 2019-12-20 20:13 ` Brian Gix
2019-12-20 20:13 ` [PATCH BlueZ 2/2] mesh: Recognize SNBs in SecondsSinceLastHeard Brian Gix
2019-12-24 19:03 ` [PATCH BlueZ 0/2] mesh: Fix some SNB details Gix, Brian
2 siblings, 0 replies; 4+ messages in thread
From: Brian Gix @ 2019-12-20 20:13 UTC (permalink / raw)
To: linux-bluetooth; +Cc: brian.gix, inga.stotland
---
mesh/net-keys.c | 3 +++
mesh/net.c | 13 +++++++++++++
mesh/net.h | 1 +
3 files changed, 17 insertions(+)
diff --git a/mesh/net-keys.c b/mesh/net-keys.c
index 65f0808dd..6f1758fe3 100644
--- a/mesh/net-keys.c
+++ b/mesh/net-keys.c
@@ -480,6 +480,9 @@ bool net_key_beacon_refresh(uint32_t id, uint32_t iv_index, bool kr, bool ivu)
l_debug("Setting SNB: IVI: %8.8x, IVU: %d, KR: %d", iv_index, ivu, kr);
print_packet("Set SNB Beacon to", beacon, sizeof(beacon));
+ /* Propagate changes to all local nodes */
+ net_local_beacon(id, beacon);
+
/* Send one new SNB soon, after all nodes have seen it */
l_getrandom(&rand_ms, sizeof(rand_ms));
rand_ms %= 1000;
diff --git a/mesh/net.c b/mesh/net.c
index 0485086bc..5aeeab188 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -2739,6 +2739,19 @@ static void beacon_recv(void *user_data, struct mesh_io_recv_info *info,
net_key_beacon_seen(beacon_data.key_id);
}
+void net_local_beacon(uint32_t key_id, uint8_t *beacon)
+{
+ struct net_beacon_data beacon_data = {
+ .key_id = key_id,
+ .ivu = !!(beacon[2] & 0x02),
+ .kr = !!(beacon[2] & 0x01),
+ .ivi = l_get_be32(beacon + 11),
+ };
+
+ /* Deliver locally generated beacons to all nodes */
+ l_queue_foreach(nets, process_beacon, &beacon_data);
+}
+
bool mesh_net_set_beacon_mode(struct mesh_net *net, bool enable)
{
if (!net)
diff --git a/mesh/net.h b/mesh/net.h
index 07b87830d..023b61e71 100644
--- a/mesh/net.h
+++ b/mesh/net.h
@@ -280,6 +280,7 @@ uint16_t mesh_net_get_address(struct mesh_net *net);
bool mesh_net_register_unicast(struct mesh_net *net,
uint16_t unicast, uint8_t num_ele);
uint8_t mesh_net_get_num_ele(struct mesh_net *net);
+void net_local_beacon(uint32_t key_id, uint8_t *beacon);
bool mesh_net_set_beacon_mode(struct mesh_net *net, bool enable);
bool mesh_net_set_proxy_mode(struct mesh_net *net, bool enable);
bool mesh_net_set_relay_mode(struct mesh_net *net, bool enable, uint8_t cnt,
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH BlueZ 2/2] mesh: Recognize SNBs in SecondsSinceLastHeard
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
2019-12-24 19:03 ` [PATCH BlueZ 0/2] mesh: Fix some SNB details Gix, Brian
2 siblings, 0 replies; 4+ messages in thread
From: Brian Gix @ 2019-12-20 20:13 UTC (permalink / raw)
To: linux-bluetooth; +Cc: brian.gix, inga.stotland
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH BlueZ 0/2] mesh: Fix some SNB details
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 ` [PATCH BlueZ 2/2] mesh: Recognize SNBs in SecondsSinceLastHeard Brian Gix
@ 2019-12-24 19:03 ` Gix, Brian
2 siblings, 0 replies; 4+ messages in thread
From: Gix, Brian @ 2019-12-24 19:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Stotland, Inga
Patchset applied
On Fri, 2019-12-20 at 12:13 -0800, Brian Gix wrote:
> This fixes two minor flaws with Secure Net Beacons:
>
> 1. When a local node's SNB changes, all local nodes should be made aware
> of the change a the same time we start sending out that beacon.
>
> 2. The second that a remote beacon is "seen" needs to be recorded so
> that the SecondsSinceLastHeard property can be correctly updated.
>
> Brian Gix (2):
> mesh: Deliver newly composed SNBs to local nodes
> mesh: Recognize SNBs in SecondsSinceLastHeard property
>
> mesh/net-keys.c | 19 ++++++++++++++++---
> mesh/net-keys.h | 1 +
> mesh/net.c | 28 ++++++++++++++++++++++++++++
> mesh/net.h | 1 +
> 4 files changed, 46 insertions(+), 3 deletions(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-24 19:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH BlueZ 2/2] mesh: Recognize SNBs in SecondsSinceLastHeard Brian Gix
2019-12-24 19:03 ` [PATCH BlueZ 0/2] mesh: Fix some SNB details Gix, Brian
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).