Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ] mesh: Fix calculation of model publication period
@ 2020-07-28 18:10 Inga Stotland
  2020-07-29 19:00 ` Gix, Brian
  0 siblings, 1 reply; 2+ messages in thread
From: Inga Stotland @ 2020-07-28 18:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, 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(-)

diff --git a/mesh/model.c b/mesh/model.c
index 31197b363..ef7668147 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -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;
 	}
 }
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ] mesh: Fix calculation of model publication period
  2020-07-28 18:10 [PATCH BlueZ] mesh: Fix calculation of model publication period Inga Stotland
@ 2020-07-29 19:00 ` Gix, Brian
  0 siblings, 0 replies; 2+ messages in thread
From: Gix, Brian @ 2020-07-29 19:00 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga

Applied
On Tue, 2020-07-28 at 11:10 -0700, Inga Stotland wrote:
> 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(-)
> 
> diff --git a/mesh/model.c b/mesh/model.c
> index 31197b363..ef7668147 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -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;
>  	}
>  }
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 18:10 [PATCH BlueZ] mesh: Fix calculation of model publication period Inga Stotland
2020-07-29 19:00 ` Gix, Brian

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git