Skip to contentSkip to conversation

mesh: Fix long MIC usage in segmented messages

PATCH In review Brian Gix 2 participants 6 messages May 23, 2019 – May 28, 2019 Bluetooth drivers

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

PATCH 1/1 mesh: Fix long MIC usage in segmented messages

From: Jakub Witowski <[email protected]>

Contrary to the comment, implementation used a 8-byte MIC even if this generated an additional segment.

---
 mesh/model.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/model.c +4 -1
index 034d54496..90bb62db8 100644
@@ -40,6 +40,9 @@
 #include "mesh/util.h"
 #include "mesh/model.h"
 
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
 struct mesh_model {
 	const struct mesh_model_ops *cbs;
 	void *user_data;
@@ -451,7 +454,7 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 
 	/* Use large MIC if it doesn't affect segmentation */
 	if (msg_len > 11 && msg_len <= 376) {
-		if ((out_len / 12) == ((out_len + 4) / 12)) {
+		if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
 			szmic = true;
 			out_len = msg_len + sizeof(uint64_t);
 		}
Signature · 1 line
2.14.5
author
#1 lore raw

Hi Jakub and Michal,

If you have no objections, this will be the version of the Long MIC patch I will be applying.

Quoted 43 lines

-----Original Message-----
From: Gix, Brian
Sent: Thursday, May 23, 2019 10:53 AM
To: [email protected]
Cc: Stotland, Inga <[email protected]>; Gix, Brian <[email protected]>; [email protected]; michal.lowas- [email protected]
Subject: [PATCH BlueZ] mesh: Fix long MIC usage in segmented messages

From: Jakub Witowski <[email protected]>

Contrary to the comment, implementation used a 8-byte MIC even if this generated an additional segment.

---
 mesh/model.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/model.c index 034d54496..90bb62db8 renamed from mesh/model.c +0 -0

100644

mesh/model.c +4 -1
@@ -40,6 +40,9 @@
 #include "mesh/util.h"
 #include "mesh/model.h"
 
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
 struct mesh_model {
 	const struct mesh_model_ops *cbs;
 	void *user_data;
@@ -451,7 +454,7 @@ static bool msg_send(struct mesh_node *node, bool
 credential, uint16_t src,
 
 	/* Use large MIC if it doesn't affect segmentation */
 	if (msg_len > 11 && msg_len <= 376) {
-		if ((out_len / 12) == ((out_len + 4) / 12)) {
+		if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
 			szmic = true;
 			out_len = msg_len + sizeof(uint64_t);

}
--
2.14.5

author
#2 lore raw
In reply to Brian Gix

Patch Applied

Quoted 31 lines · Brian Gix

From: Jakub Witowski <[email protected]>

Contrary to the comment, implementation used a 8-byte MIC even if this generated an additional segment.

---
 mesh/model.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/model.c +4 -1
index 034d54496..90bb62db8 100644
@@ -40,6 +40,9 @@
 #include "mesh/util.h"
 #include "mesh/model.h"
 
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
 struct mesh_model {
 	const struct mesh_model_ops *cbs;
 	void *user_data;
@@ -451,7 +454,7 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 
 	/* Use large MIC if it doesn't affect segmentation */
 	if (msg_len > 11 && msg_len <= 376) {
-		if ((out_len / 12) == ((out_len + 4) / 12)) {
+		if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
 			szmic = true;
 			out_len = msg_len + sizeof(uint64_t);
 		}
#3 lore raw

Hi Brian,

Quoted 1 line · Brian

Patch Applied

Sorry for radio silence, I was away for last two weeks.

Thank you!

Signature · 3 lines
Michał Lowas-Rzechonek <[email protected]>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND
author
#4 lore raw
In reply to Brian Gix

Hi Jakub and Michal,

If you guys are OK with this, this is the version of the patch on long MICs and segment count I will be applying.

Quoted 31 lines · Brian Gix

From: Jakub Witowski <[email protected]>

Contrary to the comment, implementation used a 8-byte MIC even if this generated an additional segment.

---
 mesh/model.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/model.c +4 -1
index 034d54496..90bb62db8 100644
@@ -40,6 +40,9 @@
 #include "mesh/util.h"
 #include "mesh/model.h"
 
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
 struct mesh_model {
 	const struct mesh_model_ops *cbs;
 	void *user_data;
@@ -451,7 +454,7 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 
 	/* Use large MIC if it doesn't affect segmentation */
 	if (msg_len > 11 && msg_len <= 376) {
-		if ((out_len / 12) == ((out_len + 4) / 12)) {
+		if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
 			szmic = true;
 			out_len = msg_len + sizeof(uint64_t);
 		}
#5 lore raw

Yes, it's fine.

Signature · 11 lines
Michał Lowas-Rzechonek
Lambda Team Leader

Silvair
Jasnogórska 44
31-358 Krakow
POLAND

http://www.silvair.com

pon., 27 maj 2019 o 20:14 Gix, Brian <[email protected]> napisał(a):
Quoted 38 lines

Hi Jakub and Michal,

If you guys are OK with this, this is the version of the patch on long MICs and segment count I will be applying.

Quoted 31 lines · Brian Gix

From: Jakub Witowski <[email protected]>

Contrary to the comment, implementation used a 8-byte MIC even if this generated an additional segment.

---
 mesh/model.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/model.c +4 -1
index 034d54496..90bb62db8 100644
@@ -40,6 +40,9 @@
 #include "mesh/util.h"
 #include "mesh/model.h"
 
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
 struct mesh_model {
      const struct mesh_model_ops *cbs;
      void *user_data;
@@ -451,7 +454,7 @@ static bool msg_send(struct mesh_node *node, bool credential, uint16_t src,
 
      /* Use large MIC if it doesn't affect segmentation */
      if (msg_len > 11 && msg_len <= 376) {
-             if ((out_len / 12) == ((out_len + 4) / 12)) {
+             if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
                      szmic = true;
                      out_len = msg_len + sizeof(uint64_t);
              }