50 #define PRINTF(...) printf(__VA_ARGS__)
55 #ifdef NULLRDC_CONF_ADDRESS_FILTER
56 #define NULLRDC_ADDRESS_FILTER NULLRDC_CONF_ADDRESS_FILTER
58 #define NULLRDC_ADDRESS_FILTER 1
60 #define NULLRDC_802154_AUTOACK 1
62 #ifndef NULLRDC_802154_AUTOACK
63 #ifdef NULLRDC_CONF_802154_AUTOACK
64 #define NULLRDC_802154_AUTOACK NULLRDC_CONF_802154_AUTOACK
66 #define NULLRDC_802154_AUTOACK 0
70 #ifndef NULLRDC_802154_AUTOACK_HW
71 #ifdef NULLRDC_CONF_802154_AUTOACK_HW
72 #define NULLRDC_802154_AUTOACK_HW NULLRDC_CONF_802154_AUTOACK_HW
74 #define NULLRDC_802154_AUTOACK_HW 0
78 #if NULLRDC_802154_AUTOACK
80 #include "dev/watchdog.h"
82 #define ACK_WAIT_TIME RTIMER_SECOND / 2500
83 #define AFTER_ACK_DETECTED_WAIT_TIME RTIMER_SECOND / 1500
87 #if NULLRDC_802154_AUTOACK || NULLRDC_802154_AUTOACK_HW
93 #ifdef NETSTACK_CONF_MAC_SEQNO_HISTORY
94 #define MAX_SEQNOS NETSTACK_CONF_MAC_SEQNO_HISTORY
99 static struct seqno received_seqnos[MAX_SEQNOS];
104 send_packet(mac_callback_t sent,
void *ptr)
108 #if NULLRDC_802154_AUTOACK || NULLRDC_802154_AUTOACK_HW
109 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
112 if(NETSTACK_FRAMER.create() == 0) {
114 PRINTF(
"nullrdc: send failed, too large header\n");
115 ret = MAC_TX_ERR_FATAL;
118 #if NULLRDC_802154_AUTOACK
125 is_broadcast =
rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
128 if(NETSTACK_RADIO.receiving_packet() ||
129 (!is_broadcast && NETSTACK_RADIO.pending_packet())) {
147 while(RTIMER_CLOCK_LT(
RTIMER_NOW(), wt + ACK_WAIT_TIME));
150 if(NETSTACK_RADIO.receiving_packet() ||
151 NETSTACK_RADIO.pending_packet() ||
152 NETSTACK_RADIO.channel_clear() == 0) {
154 uint8_t ackbuf[ACK_LEN];
159 wt + AFTER_ACK_DETECTED_WAIT_TIME));
161 if(NETSTACK_RADIO.pending_packet()) {
162 len = NETSTACK_RADIO.read(ackbuf, ACK_LEN);
163 if(len == ACK_LEN && ackbuf[2] == dsn) {
174 case RADIO_TX_COLLISION:
189 case RADIO_TX_COLLISION:
202 mac_call_sent_callback(sent, ptr, ret, 1);
208 PRINTF(
"nullrdc: got packet\n");
209 #if NULLRDC_802154_AUTOACK
215 if(NETSTACK_FRAMER.parse() == 0) {
217 #if NULLRDC_ADDRESS_FILTER
218 }
else if(!
rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
222 PRINTF(
"nullrdc: not for us\n");
225 #if NULLRDC_802154_AUTOACK || NULLRDC_802154_AUTOACK_HW
229 for(i = 0; i < MAX_SEQNOS; ++i) {
230 if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno &&
232 &received_seqnos[i].sender)) {
234 PRINTF(
"nullrdc: drop duplicate link layer packet %u\n",
235 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
239 for(i = MAX_SEQNOS - 1; i > 0; --i) {
240 memcpy(&received_seqnos[i], &received_seqnos[i - 1],
241 sizeof(
struct seqno));
243 received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
245 packetbuf_addr(PACKETBUF_ADDR_SENDER));
247 NETSTACK_MAC.input();
254 return NETSTACK_RADIO.on();
258 off(
int keep_radio_on)
261 return NETSTACK_RADIO.on();
263 return NETSTACK_RADIO.off();
267 static unsigned short
268 channel_check_interval(
void)