From 4deba89f81105114a08383b0b2a65cd6f8bb045b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Fri, 15 Nov 2013 19:31:02 +0100 Subject: [PATCH] rdc: duplicate packets: Keep only the last sequence number for each address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to IEEE 802.15.4e (§6.4.3.9), in order to detect duplicate received MAC-layer frames, only the most recently received frame's sequence number needs to be stored for each unique device address. Doing so limits the possible false duplicate packet detections to a single sequence number. This also allows to keep the last sequence number of more device addresses for the same value of MAX_SEQNOS. Signed-off-by: Benoît Thébaudeau --- core/net/mac/mac-sequence.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/core/net/mac/mac-sequence.c b/core/net/mac/mac-sequence.c index 5b6502aa6..be646607f 100644 --- a/core/net/mac/mac-sequence.c +++ b/core/net/mac/mac-sequence.c @@ -72,11 +72,13 @@ mac_sequence_is_duplicate(void) * packet with the last few ones we saw. */ for(i = 0; i < MAX_SEQNOS; ++i) { - if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno && - rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), + if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), &received_seqnos[i].sender)) { - /* Duplicate packet. */ - return 1; + if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno) { + /* Duplicate packet. */ + return 1; + } + break; } } return 0; @@ -85,10 +87,20 @@ mac_sequence_is_duplicate(void) void mac_sequence_register_seqno(void) { - int i; + int i, j; - for(i = MAX_SEQNOS - 1; i > 0; --i) { - memcpy(&received_seqnos[i], &received_seqnos[i - 1], sizeof(struct seqno)); + /* Locate possible previous sequence number for this address. */ + for(i = 0; i < MAX_SEQNOS; ++i) { + if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), + &received_seqnos[i].sender)) { + i++; + break; + } + } + + /* Keep the last sequence number for each address as per 802.15.4e. */ + for(j = i - 1; j > 0; --j) { + memcpy(&received_seqnos[j], &received_seqnos[j - 1], sizeof(struct seqno)); } received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID); rimeaddr_copy(&received_seqnos[0].sender,