mesh: Correct HB sub state updates
authorIsak Westin <isak.westin@loytec.com>
Mon, 26 Sep 2022 13:01:09 +0000 (15:01 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
If heartbeat subscription is disabled, all fields should be set to zero
but collected data should be preserved. If HB subscription is enabled,
the collected data should be reset (which includes Min Hops = 0x7f).
HB subscription is disabled by setting any of the following fields to
zero: Source, destination or period log.
HB subscription is enabled by setting all the same fields to valid values.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/cfgmod-server.c
mesh/net.c

index 9c5edf5514918ef6bcd1d20a1a0156e7f5cfa0f5..55a2d896bb4c9e6962c88a28b7104db9e9500ed9 100644 (file)
@@ -496,7 +496,7 @@ static uint16_t hb_subscription_get(struct mesh_node *node, int status)
        n += 2;
        msg[n++] = uint32_to_log(time_now.tv_sec);
        msg[n++] = sub->count != 0xffff ? uint32_to_log(sub->count) : 0xff;
-       msg[n++] = sub->count ? sub->min_hops : 0;
+       msg[n++] = sub->min_hops;
        msg[n++] = sub->max_hops;
 
        return n;
index ad9ff15e569078d77c3f5a493acc084fbdaeed72..faa7aa9802e2a2d4f8481e6bb5d3c41eada8e830 100644 (file)
@@ -3606,24 +3606,14 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
                return MESH_STATUS_UNSPECIFIED_ERROR;
 
        /* Check if the subscription should be disabled */
-       if (IS_UNASSIGNED(src) || IS_UNASSIGNED(dst)) {
+       if (IS_UNASSIGNED(src) || IS_UNASSIGNED(dst) || !period_log) {
                if (IS_GROUP(sub->dst))
                        mesh_net_dst_unreg(net, sub->dst);
 
+               /* Preserve collected data, but disable */
                sub->enabled = false;
                sub->dst = UNASSIGNED_ADDRESS;
                sub->src = UNASSIGNED_ADDRESS;
-               sub->count = 0;
-               sub->period = 0;
-               sub->min_hops = 0;
-               sub->max_hops = 0;
-
-       } else if (!period_log && src == sub->src && dst == sub->dst) {
-               if (IS_GROUP(sub->dst))
-                       mesh_net_dst_unreg(net, sub->dst);
-
-               /* Preserve collected data, but disable */
-               sub->enabled = false;
                sub->period = 0;
 
        } else {
@@ -3635,12 +3625,12 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
                                mesh_net_dst_reg(net, dst);
                }
 
-               sub->enabled = !!period_log;
+               sub->enabled = true;
                sub->src = src;
                sub->dst = dst;
                sub->count = 0;
                sub->period = log_to_uint32(period_log);
-               sub->min_hops = 0x00;
+               sub->min_hops = 0x7f;
                sub->max_hops = 0x00;
                gettimeofday(&time_now, NULL);
                sub->start = time_now.tv_sec;
@@ -3654,8 +3644,6 @@ int mesh_net_set_heartbeat_sub(struct mesh_net *net, uint16_t src, uint16_t dst,
                return MESH_STATUS_SUCCESS;
        }
 
-       sub->min_hops = 0xff;
-
        if (!sub->timer)
                sub->timer = l_timeout_create(sub->period, hb_sub_timeout_func,
                                                                net, NULL);