linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] mesh: fix node default TTL
@ 2019-11-11 12:00 Aurelien Jarno
  2019-11-19 23:54 ` Gix, Brian
  0 siblings, 1 reply; 2+ messages in thread
From: Aurelien Jarno @ 2019-11-11 12:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Aurelien Jarno

There is a confusion between the node default TTL (section 4.2.7) and
the publish TTL (section 4.2.2.5):

- The node default TTL can only take values 0x00, and 0x02 to 0x7f. The
  value 0xff is not prohibited.
- The publish TTL can take values 0x00 to 0x7f, as well as 0xff which
  means use the node default TTL.

Currently the default node TTL is set to 0xff (DEFAULT_TTL), and
read_default_ttl() also allows such a value. This patch fixes that to
use 0x7f (TTL_MASK) as the default value instead.

Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f
(TTL_MASK) for the upper allowed limit.
---
 mesh/mesh-config-json.c | 2 +-
 mesh/node.c             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index b2cff6824..5ca2961b0 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -358,7 +358,7 @@ static bool read_default_ttl(json_object *jobj, uint8_t *ttl)
 	if (!val && errno == EINVAL)
 		return false;
 
-	if (val < 0 || val == 1 || val > DEFAULT_TTL)
+	if (val < 0 || val == 1 || val > TTL_MASK)
 		return false;
 
 	*ttl = (uint8_t) val;
diff --git a/mesh/node.c b/mesh/node.c
index e23f32dd1..5dcffe6f7 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -672,7 +672,7 @@ struct l_queue *node_get_element_models(struct mesh_node *node,
 uint8_t node_default_ttl_get(struct mesh_node *node)
 {
 	if (!node)
-		return DEFAULT_TTL;
+		return TTL_MASK;
 	return node->ttl;
 }
 
@@ -1352,7 +1352,7 @@ static void set_defaults(struct mesh_node *node)
 	node->friend = MESH_MODE_UNSUPPORTED;
 	node->beacon = MESH_MODE_DISABLED;
 	node->relay.mode = MESH_MODE_DISABLED;
-	node->ttl = DEFAULT_TTL;
+	node->ttl = TTL_MASK;
 	node->seq_number = DEFAULT_SEQUENCE_NUMBER;
 
 	/* Add configuration server model on primary element */
-- 
2.24.0


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

* Re: [PATCH BlueZ] mesh: fix node default TTL
  2019-11-11 12:00 [PATCH BlueZ] mesh: fix node default TTL Aurelien Jarno
@ 2019-11-19 23:54 ` Gix, Brian
  0 siblings, 0 replies; 2+ messages in thread
From: Gix, Brian @ 2019-11-19 23:54 UTC (permalink / raw)
  To: aurelien, linux-bluetooth

Applied, Thanks

On Mon, 2019-11-11 at 13:00 +0100, Aurelien Jarno wrote:
> There is a confusion between the node default TTL (section 4.2.7) and
> the publish TTL (section 4.2.2.5):
> 
> - The node default TTL can only take values 0x00, and 0x02 to 0x7f. The
>   value 0xff is not prohibited.
> - The publish TTL can take values 0x00 to 0x7f, as well as 0xff which
>   means use the node default TTL.
> 
> Currently the default node TTL is set to 0xff (DEFAULT_TTL), and
> read_default_ttl() also allows such a value. This patch fixes that to
> use 0x7f (TTL_MASK) as the default value instead.
> 
> Note that the code handling OP_CONFIG_DEFAULT_TTL_SET correctly use 0x7f
> (TTL_MASK) for the upper allowed limit.
> ---
>  mesh/mesh-config-json.c | 2 +-
>  mesh/node.c             | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
> index b2cff6824..5ca2961b0 100644
> --- a/mesh/mesh-config-json.c
> +++ b/mesh/mesh-config-json.c
> @@ -358,7 +358,7 @@ static bool read_default_ttl(json_object *jobj, uint8_t *ttl)
>  	if (!val && errno == EINVAL)
>  		return false;
>  
> -	if (val < 0 || val == 1 || val > DEFAULT_TTL)
> +	if (val < 0 || val == 1 || val > TTL_MASK)
>  		return false;
>  
>  	*ttl = (uint8_t) val;
> diff --git a/mesh/node.c b/mesh/node.c
> index e23f32dd1..5dcffe6f7 100644
> --- a/mesh/node.c
> +++ b/mesh/node.c
> @@ -672,7 +672,7 @@ struct l_queue *node_get_element_models(struct mesh_node *node,
>  uint8_t node_default_ttl_get(struct mesh_node *node)
>  {
>  	if (!node)
> -		return DEFAULT_TTL;
> +		return TTL_MASK;
>  	return node->ttl;
>  }
>  
> @@ -1352,7 +1352,7 @@ static void set_defaults(struct mesh_node *node)
>  	node->friend = MESH_MODE_UNSUPPORTED;
>  	node->beacon = MESH_MODE_DISABLED;
>  	node->relay.mode = MESH_MODE_DISABLED;
> -	node->ttl = DEFAULT_TTL;
> +	node->ttl = TTL_MASK;
>  	node->seq_number = DEFAULT_SEQUENCE_NUMBER;
>  
>  	/* Add configuration server model on primary element */

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

end of thread, other threads:[~2019-11-19 23:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 12:00 [PATCH BlueZ] mesh: fix node default TTL Aurelien Jarno
2019-11-19 23:54 ` 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).