mesh: Clear HB sub status field if disabled
authorIsak Westin <isak.westin@loytec.com>
Mon, 26 Sep 2022 13:01:10 +0000 (15:01 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
When replying to a HB subscription get message, and the current state of
source or destination fields is zero (which means that HB subscription
is disabled), all fields in the status reply should be zero.

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

index 55a2d89..7044b67 100644 (file)
@@ -470,7 +470,7 @@ static uint8_t uint32_to_log(uint32_t value)
        return ret;
 }
 
-static uint16_t hb_subscription_get(struct mesh_node *node, int status)
+static uint16_t hb_subscription_status(struct mesh_node *node, int status)
 {
        struct mesh_net *net = node_get_net(node);
        struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);
@@ -502,6 +502,28 @@ static uint16_t hb_subscription_get(struct mesh_node *node, int status)
        return n;
 }
 
+static uint16_t hb_subscription_get(struct mesh_node *node, int status)
+{
+       struct mesh_net *net = node_get_net(node);
+       struct mesh_net_heartbeat_sub *sub = mesh_net_get_heartbeat_sub(net);
+
+       /*
+        * MshPRFv1.0.1 section 4.4.1.2.16, Heartbeat Subscription state:
+        * If this is a GET request and the source or destination is unassigned,
+        * all fields shall be set to zero in the status reply.
+        */
+       if (IS_UNASSIGNED(sub->src) || IS_UNASSIGNED(sub->dst)) {
+               uint16_t n;
+
+               n = mesh_model_opcode_set(OP_CONFIG_HEARTBEAT_SUB_STATUS, msg);
+               memset(msg + n, 0, 9);
+               n += 9;
+               return n;
+       }
+
+       return hb_subscription_status(node, status);
+}
+
 static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)
 {
        uint16_t src, dst;
@@ -525,7 +547,7 @@ static uint16_t hb_subscription_set(struct mesh_node *node, const uint8_t *pkt)
 
        status = mesh_net_set_heartbeat_sub(net, src, dst, period_log);
 
-       return hb_subscription_get(node, status);
+       return hb_subscription_status(node, status);
 }
 
 static uint16_t hb_publication_get(struct mesh_node *node, int status)