47#include "contiki-net.h"
48#include "lib/random.h"
54 clock_time_t timestamp;
58#ifdef NETSTACK_CONF_MAC_SEQNO_MAX_AGE
59#define SEQNO_MAX_AGE NETSTACK_CONF_MAC_SEQNO_MAX_AGE
61#define SEQNO_MAX_AGE (20 * CLOCK_SECOND)
64#ifdef NETSTACK_CONF_MAC_SEQNO_HISTORY
65#define MAX_SEQNOS NETSTACK_CONF_MAC_SEQNO_HISTORY
69static struct seqno received_seqnos[MAX_SEQNOS];
71static uint8_t mac_dsn;
83 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, mac_dsn++);
96 for(i = 0; i < MAX_SEQNOS; ++i) {
98 &received_seqnos[i].sender)) {
99 if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) == received_seqnos[i].seqno) {
101 if(now - received_seqnos[i].timestamp <= SEQNO_MAX_AGE) {
121 for(i = 0; i < MAX_SEQNOS; ++i) {
123 &received_seqnos[i].sender)) {
130 for(j = i - 1; j > 0; --j) {
131 memcpy(&received_seqnos[j], &received_seqnos[j - 1],
sizeof(
struct seqno));
133 received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
136 packetbuf_addr(PACKETBUF_ADDR_SENDER));
clock_time_t clock_time(void)
Get the current clock time.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
bool linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
void mac_sequence_set_dsn(void)
Sets and increments the destination sequence number.
int mac_sequence_is_duplicate(void)
Tell whether the packetbuf is a duplicate packet.
void mac_sequence_register_seqno(void)
Register the sequence number of the packetbuf.
void mac_sequence_init(void)
brief Initializes the destination sequence number to a random value.
Header file for MAC sequence numbers management.
Header file for the Packet buffer (packetbuf) management.