Merge pull request #1161 from g-oikonomou/contrib/contikimac-sw-ack

Implement TX of S/W ACKs with ContikiMAC
This commit is contained in:
Simon Duquennoy 2015-08-04 13:15:03 +02:00
commit dc4de9d001

View file

@ -203,6 +203,12 @@ static int we_are_receiving_burst = 0;
to a neighbor for which we have a phase lock. */ to a neighbor for which we have a phase lock. */
#define MAX_PHASE_STROBE_TIME RTIMER_ARCH_SECOND / 60 #define MAX_PHASE_STROBE_TIME RTIMER_ARCH_SECOND / 60
#ifdef CONTIKIMAC_CONF_SEND_SW_ACK
#define CONTIKIMAC_SEND_SW_ACK CONTIKIMAC_CONF_SEND_SW_ACK
#else
#define CONTIKIMAC_SEND_SW_ACK 0
#endif
#define ACK_LEN 3 #define ACK_LEN 3
#include <stdio.h> #include <stdio.h>
@ -873,10 +879,26 @@ static void
input_packet(void) input_packet(void)
{ {
static struct ctimer ct; static struct ctimer ct;
int duplicate = 0;
#if CONTIKIMAC_SEND_SW_ACK
int original_datalen;
uint8_t *original_dataptr;
original_datalen = packetbuf_datalen();
original_dataptr = packetbuf_dataptr();
#endif
if(!we_are_receiving_burst) { if(!we_are_receiving_burst) {
off(); off();
} }
if(packetbuf_datalen() == ACK_LEN) {
/* Ignore ack packets */
PRINTF("ContikiMAC: ignored ack\n");
return;
}
/* printf("cycle_start 0x%02x 0x%02x\n", cycle_start, cycle_start % CYCLE_TIME);*/ /* printf("cycle_start 0x%02x 0x%02x\n", cycle_start, cycle_start % CYCLE_TIME);*/
if(packetbuf_totlen() > 0 && NETSTACK_FRAMER.parse() >= 0) { if(packetbuf_totlen() > 0 && NETSTACK_FRAMER.parse() >= 0) {
@ -904,12 +926,13 @@ input_packet(void)
#if RDC_WITH_DUPLICATE_DETECTION #if RDC_WITH_DUPLICATE_DETECTION
/* Check for duplicate packet. */ /* Check for duplicate packet. */
if(mac_sequence_is_duplicate()) { duplicate = mac_sequence_is_duplicate();
if(duplicate) {
/* Drop the packet. */ /* Drop the packet. */
/* printf("Drop duplicate ContikiMAC layer packet\n");*/ PRINTF("contikimac: Drop duplicate\n");
return; } else {
mac_sequence_register_seqno();
} }
mac_sequence_register_seqno();
#endif /* RDC_WITH_DUPLICATE_DETECTION */ #endif /* RDC_WITH_DUPLICATE_DETECTION */
#if CONTIKIMAC_CONF_COMPOWER #if CONTIKIMAC_CONF_COMPOWER
@ -927,7 +950,30 @@ input_packet(void)
#endif /* CONTIKIMAC_CONF_COMPOWER */ #endif /* CONTIKIMAC_CONF_COMPOWER */
PRINTDEBUG("contikimac: data (%u)\n", packetbuf_datalen()); PRINTDEBUG("contikimac: data (%u)\n", packetbuf_datalen());
NETSTACK_MAC.input();
#if CONTIKIMAC_SEND_SW_ACK
{
frame802154_t info154;
frame802154_parse(original_dataptr, original_datalen, &info154);
if(info154.fcf.frame_type == FRAME802154_DATAFRAME &&
info154.fcf.ack_required != 0 &&
linkaddr_cmp((linkaddr_t *)&info154.dest_addr,
&linkaddr_node_addr)) {
uint8_t ackdata[ACK_LEN] = {0, 0, 0};
we_are_sending = 1;
ackdata[0] = FRAME802154_ACKFRAME;
ackdata[1] = 0;
ackdata[2] = info154.seq;
NETSTACK_RADIO.send(ackdata, ACK_LEN);
we_are_sending = 0;
}
}
#endif /* CONTIKIMAC_SEND_SW_ACK */
if(!duplicate) {
NETSTACK_MAC.input();
}
return; return;
} else { } else {
PRINTDEBUG("contikimac: data not for us\n"); PRINTDEBUG("contikimac: data not for us\n");