csma: Initialize sequence number with random value

According to IEEE 802.15.4 (§5.1.6.1, §6.4.2), the MAC sequence numbers should
be initialized to random values. This was already the case in
framer-802154.c:create(), but not in csma.c:send_packet(), sometimes causing
false detections of duplicate MAC-layer packets in other devices when a device
was restarted too quickly. This patch decreases the probability of such an
event.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
This commit is contained in:
Benoît Thébaudeau 2013-11-15 19:05:52 +01:00
parent acee82abbb
commit 14db3382af

View file

@ -306,9 +306,16 @@ send_packet(mac_callback_t sent, void *ptr)
{
struct rdc_buf_list *q;
struct neighbor_queue *n;
static uint8_t initialized = 0;
static uint16_t seqno;
const rimeaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
if(!initialized) {
initialized = 1;
/* Initialize the sequence number to a random value as per 802.15.4. */
seqno = random_rand();
}
if(seqno == 0) {
/* PACKETBUF_ATTR_MAC_SEQNO cannot be zero, due to a pecuilarity
in framer-802154.c. */