mesh: Fix long MIC usage in segmented messages
authorJakub Witowski <jakub.witowski@silvair.com>
Fri, 24 May 2019 14:48:10 +0000 (07:48 -0700)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 14:28:04 +0000 (19:58 +0530)
Contrary to the comment, implementation used a 8-byte MIC even if this
generated an additional segment.

Change-Id: I7e718efbe401a3312871f2a4567050dc1805a508
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/model.c

index 034d544..90bb62d 100644 (file)
@@ -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);
                }