summaryrefslogtreecommitdiff
path: root/mesh/mesh-config-json.c
diff options
context:
space:
mode:
authorJakub Witowski <jakub.witowski@silvair.com>2020-01-16 13:45:02 +0100
committerBrian Gix <brian.gix@intel.com>2020-01-16 08:45:31 -0800
commit6a889a28f18d081785e53419f663ce5e4636c74d (patch)
tree9b1661675fc680c2423abb3d52aa1b020bba2d68 /mesh/mesh-config-json.c
parentb31eee890786bae5ced19cca099f6fee4e310772 (diff)
downloadbluez-6a889a28f18d081785e53419f663ce5e4636c74d.tar.gz
mesh: Sequence number related fixes
Diffstat (limited to 'mesh/mesh-config-json.c')
-rw-r--r--mesh/mesh-config-json.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 755caab0e..5855149e3 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -40,6 +40,7 @@
#include "mesh/mesh-defs.h"
#include "mesh/util.h"
#include "mesh/mesh-config.h"
+#include "mesh/net.h"
/* To prevent local node JSON cache thrashing, minimum update times */
#define MIN_SEQ_CACHE_TRIGGER 32
@@ -365,7 +366,7 @@ static bool read_seq_number(json_object *jobj, uint32_t *seq_number)
if (!val && errno == EINVAL)
return false;
- if (val < 0 || val > 0xffffff)
+ if (val < 0 || val > SEQ_MASK + 1)
return false;
*seq_number = (uint32_t) val;
@@ -2019,10 +2020,21 @@ bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq,
if (cached < seq + MIN_SEQ_CACHE_VALUE)
cached = seq + MIN_SEQ_CACHE_VALUE;
- l_debug("Seq Cache: %d -> %d", seq, cached);
+ /* Cap the seq cache maximum to fixed out-of-range value.
+ * If daemon restarts with out-of-range value, no packets
+ * are to be sent until IV Update procedure completes.
+ */
+ if (cached > SEQ_MASK)
+ cached = SEQ_MASK + 1;
cfg->write_seq = seq;
+ /* Don't rewrite NVM storage if unchanged */
+ if (value == (int) cached)
+ return true;
+
+ l_debug("Seq Cache: %d -> %d", seq, cached);
+
if (!write_int(cfg->jnode, "sequenceNumber", cached))
return false;