Skip to contentSkip to conversation

mesh: Fix calculation of model publication period

PATCH Applied Inga Stotland 2 participants 2 messages Jul 28, 2020 – Jul 29, 2020 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: Fix calculation of model publication period

This fixes the extraction of bit fields from model publication period octet received as part of Congif Publication Set message.

The step resolution field is extracted as upper 2 bits (shift by 6) and the number of steps field is extracted by masking lower 6 bits.

---
 mesh/model.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
mesh/model.c +8 -7
index 31197b363..ef7668147 100644
@@ -170,20 +170,21 @@ static struct mesh_model *get_model(struct mesh_node *node, uint8_t ele_idx,
 
 static uint32_t pub_period_to_ms(uint8_t pub_period)
 {
-	int n;
+	int step_res, num_steps;
 
-	n = pub_period >> 2;
+	step_res = pub_period >> 6;
+	num_steps = pub_period & 0x3f;
 
-	switch (pub_period & 0x3) {
+	switch (step_res) {
 	default:
-		return n * 100;
+		return num_steps * 100;
 	case 2:
-		n *= 10;
+		num_steps *= 10;
 		/* Fall Through */
 	case 1:
-		return n * 1000;
+		return num_steps * 1000;
 	case 3:
-		return n * 10 * 60 * 1000;
+		return num_steps * 10 * 60 * 1000;
 	}
 }
 
Signature · 1 line
2.26.2
Applied
#1 lore raw

Applied

Quoted 42 lines · Inga Stotland

This fixes the extraction of bit fields from model publication period octet received as part of Congif Publication Set message.

The step resolution field is extracted as upper 2 bits (shift by 6) and the number of steps field is extracted by masking lower 6 bits.

---
 mesh/model.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
mesh/model.c +8 -7
index 31197b363..ef7668147 100644
@@ -170,20 +170,21 @@ static struct mesh_model *get_model(struct mesh_node *node, uint8_t ele_idx,
 
 static uint32_t pub_period_to_ms(uint8_t pub_period)
 {
-	int n;
+	int step_res, num_steps;
 
-	n = pub_period >> 2;
+	step_res = pub_period >> 6;
+	num_steps = pub_period & 0x3f;
 
-	switch (pub_period & 0x3) {
+	switch (step_res) {
 	default:
-		return n * 100;
+		return num_steps * 100;
 	case 2:
-		n *= 10;
+		num_steps *= 10;
 		/* Fall Through */
 	case 1:
-		return n * 1000;
+		return num_steps * 1000;
 	case 3:
-		return n * 10 * 60 * 1000;
+		return num_steps * 10 * 60 * 1000;
 	}
 }