mesh: Keep cancelled SAR data for at least 10 sec
authorIsak Westin <isak.westin@loytec.com>
Tue, 11 Oct 2022 14:06:12 +0000 (16:06 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
When a SAR transmission has been completed or cancelled, the recipent
should store the block authentication values for at least 10 seconds
and ignore new segments with the same values during this period. See
MshPRFv1.0.1 section 3.5.3.4.

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

index 8058b19..a80012d 100644 (file)
@@ -44,6 +44,7 @@
 
 #define SEG_TO 2
 #define MSG_TO 60
+#define SAR_DEL        10
 
 #define DEFAULT_TRANSMIT_COUNT         1
 #define DEFAULT_TRANSMIT_INTERVAL      100
@@ -164,6 +165,7 @@ struct mesh_sar {
        bool segmented;
        bool frnd;
        bool frnd_cred;
+       bool delete;
        uint8_t ttl;
        uint8_t last_seg;
        uint8_t key_aid;
@@ -1490,14 +1492,27 @@ static void inseg_to(struct l_timeout *seg_timeout, void *user_data)
 static void inmsg_to(struct l_timeout *msg_timeout, void *user_data)
 {
        struct mesh_net *net = user_data;
-       struct mesh_sar *sar = l_queue_remove_if(net->sar_in,
+       struct mesh_sar *sar = l_queue_find(net->sar_in,
                        match_msg_timeout, msg_timeout);
 
-       l_timeout_remove(msg_timeout);
-       if (!sar)
+       if (!sar) {
+               l_timeout_remove(msg_timeout);
                return;
+       }
 
-       sar->msg_timeout = NULL;
+       if (!sar->delete) {
+               /*
+                * Incomplete timer expired, cancel SAR and start
+                * delete timer
+                */
+               l_timeout_remove(sar->seg_timeout);
+               sar->seg_timeout = NULL;
+               sar->delete = true;
+               l_timeout_modify(sar->msg_timeout, SAR_DEL);
+               return;
+       }
+
+       l_queue_remove(net->sar_in, sar);
        mesh_sar_free(sar);
 }
 
@@ -1961,7 +1976,9 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
                        /* Re-Send ACK for full msg */
                        send_net_ack(net, sar_in, expected);
                        return true;
-               }
+               } else if (sar_in->delete)
+                       /* Ignore cancelled */
+                       return false;
        } else {
                uint16_t len = MAX_SEG_TO_LEN(segN);
 
@@ -2011,6 +2028,10 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index,
                /* Kill Inter-Seg timeout */
                l_timeout_remove(sar_in->seg_timeout);
                sar_in->seg_timeout = NULL;
+
+               /* Start delete timer */
+               sar_in->delete = true;
+               l_timeout_modify(sar_in->msg_timeout, SAR_DEL);
                return true;
        }