TSCH: use standard-compliant mac-squence module rather than custom duplicate detection

This commit is contained in:
Simon Duquennoy 2016-06-23 18:21:05 +02:00
parent a8989f9f1c
commit f1922c13b6

View file

@ -53,6 +53,7 @@
#include "net/mac/tsch/tsch-log.h" #include "net/mac/tsch/tsch-log.h"
#include "net/mac/tsch/tsch-packet.h" #include "net/mac/tsch/tsch-packet.h"
#include "net/mac/tsch/tsch-security.h" #include "net/mac/tsch/tsch-security.h"
#include "net/mac/mac-sequence.h"
#include "lib/random.h" #include "lib/random.h"
#if FRAME802154_VERSION < FRAME802154_IEEE802154E_2012 #if FRAME802154_VERSION < FRAME802154_IEEE802154E_2012
@ -69,26 +70,12 @@
/* Use to collect link statistics even on Keep-Alive, even though they were /* Use to collect link statistics even on Keep-Alive, even though they were
* not sent from an upper layer and don't have a valid packet_sent callback */ * not sent from an upper layer and don't have a valid packet_sent callback */
#ifndef TSCH_LINK_NEIGHBOR_CALLBACK #ifndef TSCH_LINK_NEIGHBOR_CALLBACK
#if NETSTACK_CONF_WITH_IPV6
void uip_ds6_link_neighbor_callback(int status, int numtx); void uip_ds6_link_neighbor_callback(int status, int numtx);
#define TSCH_LINK_NEIGHBOR_CALLBACK(dest, status, num) uip_ds6_link_neighbor_callback(status, num) #define TSCH_LINK_NEIGHBOR_CALLBACK(dest, status, num) uip_ds6_link_neighbor_callback(status, num)
#endif /* NETSTACK_CONF_WITH_IPV6 */
#endif /* TSCH_LINK_NEIGHBOR_CALLBACK */ #endif /* TSCH_LINK_NEIGHBOR_CALLBACK */
/* 802.15.4 duplicate frame detection */
struct seqno {
linkaddr_t sender;
uint8_t seqno;
};
/* Size of the sequence number history */
#ifdef NETSTACK_CONF_MAC_SEQNO_HISTORY
#define MAX_SEQNOS NETSTACK_CONF_MAC_SEQNO_HISTORY
#else /* NETSTACK_CONF_MAC_SEQNO_HISTORY */
#define MAX_SEQNOS 8
#endif /* NETSTACK_CONF_MAC_SEQNO_HISTORY */
/* Seqno history */
static struct seqno received_seqnos[MAX_SEQNOS];
/* Let TSCH select a time source with no help of an upper layer. /* Let TSCH select a time source with no help of an upper layer.
* We do so using statistics from incoming EBs */ * We do so using statistics from incoming EBs */
#if TSCH_AUTOSELECT_TIME_SOURCE #if TSCH_AUTOSELECT_TIME_SOURCE
@ -959,28 +946,16 @@ packet_input(void)
/* Seqno of 0xffff means no seqno */ /* Seqno of 0xffff means no seqno */
if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) != 0xffff) { if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) != 0xffff) {
/* Check for duplicate packet by comparing the sequence number /* Check for duplicates */
of the incoming packet with the last few ones we saw. */ duplicate = mac_sequence_is_duplicate();
int i; if(duplicate) {
for(i = 0; i < MAX_SEQNOS; ++i) { extern clock_time_t duplicate_age;
if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) == received_seqnos[i].seqno && /* Drop the packet. */
linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER), PRINTF("TSCH:! drop dup ll from %u seqno %u\n",
&received_seqnos[i].sender)) { TSCH_LOG_ID_FROM_LINKADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)),
/* Drop the packet. */ packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
PRINTF("TSCH:! drop dup ll from %u seqno %u\n", } else {
TSCH_LOG_ID_FROM_LINKADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)), mac_sequence_register_seqno();
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
duplicate = 1;
}
}
if(!duplicate) {
for(i = MAX_SEQNOS - 1; i > 0; --i) {
memcpy(&received_seqnos[i], &received_seqnos[i - 1],
sizeof(struct seqno));
}
received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
linkaddr_copy(&received_seqnos[0].sender,
packetbuf_addr(PACKETBUF_ADDR_SENDER));
} }
} }