mesh: Rearrange PB-ACK for possible session close
authorBrian Gix <brian.gix@intel.com>
Tue, 3 Dec 2019 21:04:09 +0000 (13:04 -0800)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 20:51:03 +0000 (02:21 +0530)
In certain circumstances, reception of PB-ADV messages may trigger
session close. This rearrange ACKs new verified messages before
performing call-back to avoid situations where the session no longer
exists after the message has been handled.

This caused static analysis errors during provisioning, which are now
addressed.

Change-Id: I272e8066f307374c848cb78326259b49acaf4e20
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/net.c
mesh/pb-adv.c

index b488511..5b9622b 100644 (file)
@@ -2378,7 +2378,6 @@ static enum _relay_advice packet_received(void *user_data,
                l_info("RX: App 0x%04x -> 0x%04x : TTL 0x%02x : SEQ 0x%06x",
                                        net_src, net_dst, net_ttl, net_seq);
 
-               l_debug("seq:%x seq0:%x", net_seq, net_seqZero);
                if (net_ctl) {
                        l_debug("CTL - %4.4x RX", net_seqZero);
                        if (net_opcode == NET_OP_SEG_ACKNOWLEDGE) {
index 586cd7f..27cbc46 100644 (file)
@@ -254,7 +254,7 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
        uint8_t type;
        bool first;
 
-       if (!session || pb_session != session)
+       if (!pb_session || pb_session != session)
                return;
 
        link_id = l_get_be32(pkt + 1);
@@ -426,14 +426,14 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len)
                        return;
                }
 
+               send_ack(session, session->peer_trans_num);
+
                if (session->last_peer_trans_num != session->peer_trans_num) {
                        session->got_segs = 0;
+                       session->last_peer_trans_num = session->peer_trans_num;
                        session->rx_cb(session->user_data, session->sar,
                                                        session->exp_len);
                }
-
-               session->last_peer_trans_num = session->peer_trans_num;
-               send_ack(session, session->last_peer_trans_num);
        }
 }