Bluetooth: Mesh: fix Random value generation for Private Beacons
In `private_random_update`, when first beacon is advertised, there could be a case when uptime is less then interval * 10s (`priv_random.timestamp` is equal to 0 for first beacon). Then, Private Random value will not be generated and will be set to all zeros. New Private Random must also be generated before Random Interval expires, when KR or IVU flags are changed. Reset timestamp to 0 on `bt_mesh_beacon_update` to generate new Random value. Do not generate new private random if it won't be used (Private Beacon state is not enabled). Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
This commit is contained in:
parent
b020c5d889
commit
67a33ed1a0
|
@ -153,11 +153,17 @@ static int private_random_update(void)
|
|||
uint64_t uptime = k_uptime_get();
|
||||
int err;
|
||||
|
||||
/* If private beacon will not be sent there is no point in generating new random */
|
||||
if (bt_mesh_priv_beacon_get() != BT_MESH_FEATURE_ENABLED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The Private beacon random value should change every N seconds to maintain privacy.
|
||||
* N = (10 * interval) seconds, or on every beacon creation, if the interval is 0.
|
||||
*/
|
||||
if (interval &&
|
||||
uptime - priv_random.timestamp < (10 * interval * MSEC_PER_SEC)) {
|
||||
uptime - priv_random.timestamp < (10 * interval * MSEC_PER_SEC) &&
|
||||
priv_random.timestamp != 0) {
|
||||
/* Not time yet */
|
||||
return 0;
|
||||
}
|
||||
|
@ -718,6 +724,7 @@ void bt_mesh_beacon_update(struct bt_mesh_subnet *sub)
|
|||
#if defined(CONFIG_BT_MESH_PRIV_BEACONS)
|
||||
/* Invalidate private beacon to force regeneration: */
|
||||
sub->priv_beacon_ctx.idx = priv_random.idx - 1;
|
||||
priv_random.timestamp = 0;
|
||||
#endif
|
||||
|
||||
bt_mesh_beacon_auth(keys->beacon, flags, keys->net_id, bt_mesh.iv_index,
|
||||
|
|
Loading…
Reference in a new issue