2010-01-25 12:46:44 +01:00
|
|
|
/*
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
2010-01-25 12:46:44 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
2010-02-28 11:07:17 +01:00
|
|
|
* A Carrier Sense Multiple Access (CSMA) MAC layer
|
2010-01-25 12:46:44 +01:00
|
|
|
* \author
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net/mac/csma.h"
|
2010-06-14 21:19:16 +02:00
|
|
|
#include "net/packetbuf.h"
|
|
|
|
#include "net/queuebuf.h"
|
2010-06-14 09:34:36 +02:00
|
|
|
|
|
|
|
#include "sys/ctimer.h"
|
2011-09-27 16:05:30 +02:00
|
|
|
#include "sys/clock.h"
|
2010-01-25 12:46:44 +01:00
|
|
|
|
|
|
|
#include "lib/random.h"
|
|
|
|
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
#include "net/netstack.h"
|
|
|
|
|
2010-01-25 12:46:44 +01:00
|
|
|
#include "lib/list.h"
|
|
|
|
#include "lib/memb.h"
|
|
|
|
|
2010-01-27 08:36:31 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-12-14 08:57:14 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-03-09 14:23:58 +01:00
|
|
|
#define DEBUG 0
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
#if DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else /* DEBUG */
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
/* Constants of the IEEE 802.15.4 standard */
|
|
|
|
|
|
|
|
/* macMinBE: Initial backoff exponent. Range 0--CSMA_MAX_BE */
|
|
|
|
#ifdef CSMA_CONF_MIN_BE
|
|
|
|
#define CSMA_MIN_BE CSMA_CONF_MIN_BE
|
2013-10-07 16:00:18 +02:00
|
|
|
#else
|
2016-04-22 23:27:43 +02:00
|
|
|
#define CSMA_MIN_BE 0
|
|
|
|
#endif
|
2013-10-07 16:00:18 +02:00
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
/* macMaxBE: Maximum backoff exponent. Range 3--8 */
|
|
|
|
#ifdef CSMA_CONF_MAX_BE
|
|
|
|
#define CSMA_MAX_BE CSMA_CONF_MAX_BE
|
2010-03-26 13:29:29 +01:00
|
|
|
#else
|
2016-04-22 23:27:43 +02:00
|
|
|
#define CSMA_MAX_BE 4
|
|
|
|
#endif
|
2010-03-26 13:29:29 +01:00
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
/* macMaxCSMABackoffs: Maximum number of backoffs in case of channel busy/collision. Range 0--5 */
|
|
|
|
#ifdef CSMA_CONF_MAX_BACKOFF
|
|
|
|
#define CSMA_MAX_BACKOFF CSMA_CONF_MAX_BACKOFF
|
|
|
|
#else
|
|
|
|
#define CSMA_MAX_BACKOFF 5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* macMaxFrameRetries: Maximum number of re-transmissions attampts. Range 0--7 */
|
|
|
|
#ifdef CSMA_CONF_MAX_FRAME_RETRIES
|
|
|
|
#define CSMA_MAX_MAX_FRAME_RETRIES CSMA_CONF_MAX_FRAME_RETRIES
|
|
|
|
#else
|
|
|
|
#define CSMA_MAX_MAX_FRAME_RETRIES 7
|
|
|
|
#endif
|
2010-03-26 13:29:29 +01:00
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
/* Packet metadata */
|
|
|
|
struct qbuf_metadata {
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
mac_callback_t sent;
|
|
|
|
void *cptr;
|
2011-09-27 16:05:30 +02:00
|
|
|
uint8_t max_transmissions;
|
2010-01-25 12:46:44 +01:00
|
|
|
};
|
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
/* Every neighbor has its own packet queue */
|
|
|
|
struct neighbor_queue {
|
|
|
|
struct neighbor_queue *next;
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_t addr;
|
2011-09-27 16:05:30 +02:00
|
|
|
struct ctimer transmit_timer;
|
|
|
|
uint8_t transmissions;
|
2016-04-22 23:27:43 +02:00
|
|
|
uint8_t collisions;
|
2011-09-27 16:05:30 +02:00
|
|
|
LIST_STRUCT(queued_packet_list);
|
|
|
|
};
|
2010-12-14 08:57:14 +01:00
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
/* The maximum number of co-existing neighbor queues */
|
|
|
|
#ifdef CSMA_CONF_MAX_NEIGHBOR_QUEUES
|
|
|
|
#define CSMA_MAX_NEIGHBOR_QUEUES CSMA_CONF_MAX_NEIGHBOR_QUEUES
|
|
|
|
#else
|
|
|
|
#define CSMA_MAX_NEIGHBOR_QUEUES 2
|
|
|
|
#endif /* CSMA_CONF_MAX_NEIGHBOR_QUEUES */
|
2010-01-25 12:46:44 +01:00
|
|
|
|
2013-11-20 13:40:56 +01:00
|
|
|
/* The maximum number of pending packet per neighbor */
|
|
|
|
#ifdef CSMA_CONF_MAX_PACKET_PER_NEIGHBOR
|
|
|
|
#define CSMA_MAX_PACKET_PER_NEIGHBOR CSMA_CONF_MAX_PACKET_PER_NEIGHBOR
|
|
|
|
#else
|
|
|
|
#define CSMA_MAX_PACKET_PER_NEIGHBOR MAX_QUEUED_PACKETS
|
|
|
|
#endif /* CSMA_CONF_MAX_PACKET_PER_NEIGHBOR */
|
|
|
|
|
2011-09-27 16:05:30 +02:00
|
|
|
#define MAX_QUEUED_PACKETS QUEUEBUF_NUM
|
|
|
|
MEMB(neighbor_memb, struct neighbor_queue, CSMA_MAX_NEIGHBOR_QUEUES);
|
|
|
|
MEMB(packet_memb, struct rdc_buf_list, MAX_QUEUED_PACKETS);
|
|
|
|
MEMB(metadata_memb, struct qbuf_metadata, MAX_QUEUED_PACKETS);
|
|
|
|
LIST(neighbor_list);
|
2011-01-13 20:06:22 +01:00
|
|
|
|
2010-03-09 21:38:55 +01:00
|
|
|
static void packet_sent(void *ptr, int status, int num_transmissions);
|
2011-09-27 16:05:30 +02:00
|
|
|
static void transmit_packet_list(void *ptr);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-03-17 23:29:58 +01:00
|
|
|
static struct neighbor_queue *
|
2013-12-12 23:58:52 +01:00
|
|
|
neighbor_queue_from_addr(const linkaddr_t *addr)
|
2013-03-17 23:29:58 +01:00
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct neighbor_queue *n = list_head(neighbor_list);
|
|
|
|
while(n != NULL) {
|
2013-12-12 23:58:52 +01:00
|
|
|
if(linkaddr_cmp(&n->addr, addr)) {
|
2011-09-27 16:05:30 +02:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
n = list_item_next(n);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-16 23:44:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static clock_time_t
|
2016-04-22 23:27:43 +02:00
|
|
|
backoff_period(void)
|
2010-12-16 23:44:02 +01:00
|
|
|
{
|
|
|
|
clock_time_t time;
|
|
|
|
/* The retransmission time must be proportional to the channel
|
|
|
|
check interval of the underlying radio duty cycling layer. */
|
|
|
|
time = NETSTACK_RDC.channel_check_interval();
|
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
/* If the radio duty cycle has no channel check interval, we use
|
|
|
|
* the default in IEEE 802.15.4: aUnitBackoffPeriod which is
|
|
|
|
* 20 symbols i.e. 320 usec. That is, 1/3125 second. */
|
2010-12-16 23:44:02 +01:00
|
|
|
if(time == 0) {
|
2016-04-22 23:27:43 +02:00
|
|
|
time = MAX(CLOCK_SECOND / 3125, 1);
|
2010-12-16 23:44:02 +01:00
|
|
|
}
|
|
|
|
return time;
|
|
|
|
}
|
2010-01-25 12:46:44 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-03-09 21:38:55 +01:00
|
|
|
static void
|
2011-09-27 16:05:30 +02:00
|
|
|
transmit_packet_list(void *ptr)
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct neighbor_queue *n = ptr;
|
|
|
|
if(n) {
|
|
|
|
struct rdc_buf_list *q = list_head(n->queued_packet_list);
|
|
|
|
if(q != NULL) {
|
|
|
|
PRINTF("csma: preparing number %d %p, queue len %d\n", n->transmissions, q,
|
|
|
|
list_length(n->queued_packet_list));
|
|
|
|
/* Send packets in the neighbor's list */
|
|
|
|
NETSTACK_RDC.send_list(packet_sent, n, q);
|
2010-12-14 08:57:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2016-04-22 23:27:43 +02:00
|
|
|
schedule_transmission(struct neighbor_queue *n)
|
2010-12-14 08:57:14 +01:00
|
|
|
{
|
2016-04-22 23:27:43 +02:00
|
|
|
clock_time_t delay;
|
|
|
|
int backoff_exponent; /* BE in IEEE 802.15.4 */
|
|
|
|
|
|
|
|
backoff_exponent = MIN(n->collisions, CSMA_MAX_BE);
|
|
|
|
|
|
|
|
/* Compute max delay as per IEEE 802.15.4: 2^BE-1 backoff periods */
|
|
|
|
delay = ((1 << backoff_exponent) - 1) * backoff_period();
|
|
|
|
if(delay > 0) {
|
|
|
|
/* Pick a time for next transmission */
|
|
|
|
delay = random_rand() % delay;
|
|
|
|
}
|
2015-07-14 19:04:36 +02:00
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
PRINTF("csma: scheduling transmission in %u ticks, NB=%u, BE=%u\n",
|
|
|
|
(unsigned)delay, n->collisions, backoff_exponent);
|
|
|
|
ctimer_set(&n->transmit_timer, delay, transmit_packet_list, n);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
free_packet(struct neighbor_queue *n, struct rdc_buf_list *p, int status)
|
|
|
|
{
|
2013-05-25 12:13:07 +02:00
|
|
|
if(p != NULL) {
|
|
|
|
/* Remove packet from list and deallocate */
|
|
|
|
list_remove(n->queued_packet_list, p);
|
|
|
|
|
|
|
|
queuebuf_free(p->buf);
|
|
|
|
memb_free(&metadata_memb, p->ptr);
|
|
|
|
memb_free(&packet_memb, p);
|
2013-11-20 13:09:48 +01:00
|
|
|
PRINTF("csma: free_queued_packet, queue length %d, free packets %d\n",
|
|
|
|
list_length(n->queued_packet_list), memb_numfree(&packet_memb));
|
2013-05-25 12:13:07 +02:00
|
|
|
if(list_head(n->queued_packet_list) != NULL) {
|
2011-09-27 16:05:30 +02:00
|
|
|
/* There is a next packet. We reset current tx information */
|
|
|
|
n->transmissions = 0;
|
2016-04-22 23:27:43 +02:00
|
|
|
n->collisions = CSMA_MIN_BE;
|
|
|
|
/* Schedule next transmissions */
|
|
|
|
schedule_transmission(n);
|
2011-09-27 16:05:30 +02:00
|
|
|
} else {
|
|
|
|
/* This was the last packet in the queue, we free the neighbor */
|
|
|
|
ctimer_stop(&n->transmit_timer);
|
|
|
|
list_remove(neighbor_list, n);
|
|
|
|
memb_free(&neighbor_memb, n);
|
2010-12-14 08:57:14 +01:00
|
|
|
}
|
|
|
|
}
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
}
|
2010-03-09 21:38:55 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static void
|
2016-04-01 18:41:02 +02:00
|
|
|
tx_done(int status, struct rdc_buf_list *q, struct neighbor_queue *n)
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
{
|
|
|
|
mac_callback_t sent;
|
2016-04-01 18:41:02 +02:00
|
|
|
struct qbuf_metadata *metadata;
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
void *cptr;
|
2010-03-09 14:20:08 +01:00
|
|
|
|
2016-04-01 18:41:02 +02:00
|
|
|
metadata = (struct qbuf_metadata *)q->ptr;
|
|
|
|
sent = metadata->sent;
|
|
|
|
cptr = metadata->cptr;
|
|
|
|
|
2010-03-09 14:20:08 +01:00
|
|
|
switch(status) {
|
|
|
|
case MAC_TX_OK:
|
2016-04-01 18:41:02 +02:00
|
|
|
PRINTF("csma: rexmit ok %d\n", n->transmissions);
|
2010-03-09 14:20:08 +01:00
|
|
|
break;
|
|
|
|
case MAC_TX_COLLISION:
|
2016-04-01 18:41:02 +02:00
|
|
|
case MAC_TX_NOACK:
|
|
|
|
PRINTF("csma: drop with status %d after %d transmissions, %d collisions\n",
|
|
|
|
status, n->transmissions, n->collisions);
|
2010-03-09 14:20:08 +01:00
|
|
|
break;
|
2016-04-01 18:41:02 +02:00
|
|
|
default:
|
|
|
|
PRINTF("csma: rexmit failed %d: %d\n", n->transmissions, status);
|
2010-03-09 14:20:08 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-01 18:41:02 +02:00
|
|
|
free_packet(n, q, status);
|
|
|
|
mac_call_sent_callback(sent, cptr, status, n->transmissions);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
rexmit(struct rdc_buf_list *q, struct neighbor_queue *n)
|
|
|
|
{
|
2016-04-22 23:27:43 +02:00
|
|
|
schedule_transmission(n);
|
2016-04-01 18:41:02 +02:00
|
|
|
/* This is needed to correctly attribute energy that we spent
|
|
|
|
transmitting this packet. */
|
|
|
|
queuebuf_update_attr_from_packetbuf(q->buf);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
collision(struct rdc_buf_list *q, struct neighbor_queue *n,
|
|
|
|
int num_transmissions)
|
|
|
|
{
|
|
|
|
struct qbuf_metadata *metadata;
|
|
|
|
|
|
|
|
metadata = (struct qbuf_metadata *)q->ptr;
|
|
|
|
|
|
|
|
n->collisions += num_transmissions;
|
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
if(n->collisions > CSMA_MAX_BACKOFF) {
|
|
|
|
n->collisions = CSMA_MIN_BE;
|
|
|
|
/* Increment to indicate a next retry */
|
|
|
|
n->transmissions++;
|
2016-04-01 18:41:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(n->transmissions >= metadata->max_transmissions) {
|
|
|
|
tx_done(MAC_TX_COLLISION, q, n);
|
|
|
|
} else {
|
|
|
|
PRINTF("csma: rexmit collision %d\n", n->transmissions);
|
|
|
|
rexmit(q, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
noack(struct rdc_buf_list *q, struct neighbor_queue *n, int num_transmissions)
|
|
|
|
{
|
|
|
|
struct qbuf_metadata *metadata;
|
|
|
|
|
|
|
|
metadata = (struct qbuf_metadata *)q->ptr;
|
|
|
|
|
2016-04-22 23:27:43 +02:00
|
|
|
n->collisions = CSMA_MIN_BE;
|
2016-04-01 18:41:02 +02:00
|
|
|
n->transmissions += num_transmissions;
|
|
|
|
|
|
|
|
if(n->transmissions >= metadata->max_transmissions) {
|
|
|
|
tx_done(MAC_TX_NOACK, q, n);
|
|
|
|
} else {
|
|
|
|
PRINTF("csma: rexmit noack %d\n", n->transmissions);
|
|
|
|
rexmit(q, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
tx_ok(struct rdc_buf_list *q, struct neighbor_queue *n, int num_transmissions)
|
|
|
|
{
|
2016-04-22 23:27:43 +02:00
|
|
|
n->collisions = CSMA_MIN_BE;
|
2016-04-01 18:41:02 +02:00
|
|
|
n->transmissions += num_transmissions;
|
|
|
|
tx_done(MAC_TX_OK, q, n);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
packet_sent(void *ptr, int status, int num_transmissions)
|
|
|
|
{
|
|
|
|
struct neighbor_queue *n;
|
|
|
|
struct rdc_buf_list *q;
|
|
|
|
|
|
|
|
n = ptr;
|
|
|
|
if(n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-24 08:36:18 +01:00
|
|
|
/* Find out what packet this callback refers to */
|
2013-05-25 12:13:07 +02:00
|
|
|
for(q = list_head(n->queued_packet_list);
|
|
|
|
q != NULL; q = list_item_next(q)) {
|
|
|
|
if(queuebuf_attr(q->buf, PACKETBUF_ATTR_MAC_SEQNO) ==
|
|
|
|
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 18:41:02 +02:00
|
|
|
if(q == NULL) {
|
|
|
|
PRINTF("csma: seqno %d not found\n",
|
|
|
|
packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
|
|
|
|
return;
|
|
|
|
} else if(q->ptr == NULL) {
|
|
|
|
PRINTF("csma: no metadata\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(status) {
|
|
|
|
case MAC_TX_OK:
|
|
|
|
tx_ok(q, n, num_transmissions);
|
|
|
|
break;
|
|
|
|
case MAC_TX_NOACK:
|
|
|
|
noack(q, n, num_transmissions);
|
|
|
|
break;
|
|
|
|
case MAC_TX_COLLISION:
|
|
|
|
collision(q, n, num_transmissions);
|
|
|
|
break;
|
|
|
|
case MAC_TX_DEFERRED:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tx_done(status, q, n);
|
|
|
|
break;
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
send_packet(mac_callback_t sent, void *ptr)
|
2010-01-25 12:46:44 +01:00
|
|
|
{
|
2011-09-27 16:05:30 +02:00
|
|
|
struct rdc_buf_list *q;
|
|
|
|
struct neighbor_queue *n;
|
2013-11-15 19:05:52 +01:00
|
|
|
static uint8_t initialized = 0;
|
2010-04-08 11:32:56 +02:00
|
|
|
static uint16_t seqno;
|
2013-12-12 23:58:52 +01:00
|
|
|
const linkaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
|
2011-09-27 16:05:30 +02:00
|
|
|
|
2013-11-15 19:05:52 +01:00
|
|
|
if(!initialized) {
|
|
|
|
initialized = 1;
|
|
|
|
/* Initialize the sequence number to a random value as per 802.15.4. */
|
|
|
|
seqno = random_rand();
|
|
|
|
}
|
|
|
|
|
2013-05-25 12:13:07 +02:00
|
|
|
if(seqno == 0) {
|
|
|
|
/* PACKETBUF_ATTR_MAC_SEQNO cannot be zero, due to a pecuilarity
|
|
|
|
in framer-802154.c. */
|
|
|
|
seqno++;
|
|
|
|
}
|
2010-04-08 11:32:56 +02:00
|
|
|
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
|
2011-09-27 16:05:30 +02:00
|
|
|
|
2013-03-17 23:38:14 +01:00
|
|
|
/* Look for the neighbor entry */
|
|
|
|
n = neighbor_queue_from_addr(addr);
|
|
|
|
if(n == NULL) {
|
|
|
|
/* Allocate a new neighbor entry */
|
|
|
|
n = memb_alloc(&neighbor_memb);
|
|
|
|
if(n != NULL) {
|
|
|
|
/* Init neighbor entry */
|
2013-12-12 23:58:52 +01:00
|
|
|
linkaddr_copy(&n->addr, addr);
|
2013-03-17 23:38:14 +01:00
|
|
|
n->transmissions = 0;
|
2016-04-22 23:27:43 +02:00
|
|
|
n->collisions = CSMA_MIN_BE;
|
2013-03-17 23:38:14 +01:00
|
|
|
/* Init packet list for this neighbor */
|
|
|
|
LIST_STRUCT_INIT(n, queued_packet_list);
|
|
|
|
/* Add neighbor to the list */
|
|
|
|
list_add(neighbor_list, n);
|
2011-09-27 16:05:30 +02:00
|
|
|
}
|
2013-03-17 23:38:14 +01:00
|
|
|
}
|
2010-12-14 08:57:14 +01:00
|
|
|
|
2013-03-17 23:38:14 +01:00
|
|
|
if(n != NULL) {
|
|
|
|
/* Add packet to the neighbor's queue */
|
2013-11-20 13:40:56 +01:00
|
|
|
if(list_length(n->queued_packet_list) < CSMA_MAX_PACKET_PER_NEIGHBOR) {
|
|
|
|
q = memb_alloc(&packet_memb);
|
|
|
|
if(q != NULL) {
|
|
|
|
q->ptr = memb_alloc(&metadata_memb);
|
|
|
|
if(q->ptr != NULL) {
|
|
|
|
q->buf = queuebuf_new_from_packetbuf();
|
|
|
|
if(q->buf != NULL) {
|
|
|
|
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
|
|
|
|
/* Neighbor and packet successfully allocated */
|
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
|
|
|
|
/* Use default configuration for max transmissions */
|
2016-04-22 23:27:43 +02:00
|
|
|
metadata->max_transmissions = CSMA_MAX_MAX_FRAME_RETRIES + 1;
|
2013-11-20 13:40:56 +01:00
|
|
|
} else {
|
|
|
|
metadata->max_transmissions =
|
|
|
|
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
|
|
|
|
}
|
|
|
|
metadata->sent = sent;
|
|
|
|
metadata->cptr = ptr;
|
2015-05-06 14:34:29 +02:00
|
|
|
#if PACKETBUF_WITH_PACKET_TYPE
|
2013-11-20 13:40:56 +01:00
|
|
|
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
|
|
|
|
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
|
|
|
|
list_push(n->queued_packet_list, q);
|
2015-05-06 14:34:29 +02:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2013-11-20 13:40:56 +01:00
|
|
|
list_add(n->queued_packet_list, q);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRINTF("csma: send_packet, queue length %d, free packets %d\n",
|
|
|
|
list_length(n->queued_packet_list), memb_numfree(&packet_memb));
|
|
|
|
/* If q is the first packet in the neighbor's queue, send asap */
|
|
|
|
if(list_head(n->queued_packet_list) == q) {
|
2016-04-22 23:27:43 +02:00
|
|
|
schedule_transmission(n);
|
2013-11-20 13:40:56 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memb_free(&metadata_memb, q->ptr);
|
|
|
|
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
|
|
|
}
|
|
|
|
memb_free(&packet_memb, q);
|
|
|
|
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
|
2011-09-27 16:05:30 +02:00
|
|
|
}
|
2013-11-20 13:40:56 +01:00
|
|
|
/* The packet allocation failed. Remove and free neighbor entry if empty. */
|
|
|
|
if(list_length(n->queued_packet_list) == 0) {
|
|
|
|
list_remove(neighbor_list, n);
|
|
|
|
memb_free(&neighbor_memb, n);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PRINTF("csma: Neighbor queue full\n");
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
}
|
2013-03-17 23:38:14 +01:00
|
|
|
PRINTF("csma: could not allocate packet, dropping packet\n");
|
2010-12-16 23:44:02 +01:00
|
|
|
} else {
|
2013-03-17 23:38:14 +01:00
|
|
|
PRINTF("csma: could not allocate neighbor, dropping packet\n");
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
2013-03-17 23:38:14 +01:00
|
|
|
mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1);
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
input_packet(void)
|
2010-01-25 12:46:44 +01:00
|
|
|
{
|
2013-05-24 09:21:53 +02:00
|
|
|
NETSTACK_LLSEC.input();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
on(void)
|
|
|
|
{
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
return NETSTACK_RDC.on();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
off(int keep_radio_on)
|
|
|
|
{
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
return NETSTACK_RDC.off(keep_radio_on);
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static unsigned short
|
|
|
|
channel_check_interval(void)
|
|
|
|
{
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
if(NETSTACK_RDC.channel_check_interval) {
|
|
|
|
return NETSTACK_RDC.channel_check_interval();
|
2010-01-25 12:46:44 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
static void
|
|
|
|
init(void)
|
|
|
|
{
|
|
|
|
memb_init(&packet_memb);
|
2011-09-27 16:05:30 +02:00
|
|
|
memb_init(&metadata_memb);
|
|
|
|
memb_init(&neighbor_memb);
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-01-25 12:46:44 +01:00
|
|
|
const struct mac_driver csma_driver = {
|
2010-02-23 21:42:45 +01:00
|
|
|
"CSMA",
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
init,
|
2010-01-25 12:46:44 +01:00
|
|
|
send_packet,
|
A work-in-progress rework of the Contiki MAC and radio layers. The
main ideas are:
* Separates the Contiki low-layer network stack into four layers:
network (e.g. sicslowpan / rime), Medium Access Control MAC
(e.g. CSMA), Radio Duty Cycling RDC (e.g. ContikiMAC, X-MAC), and
radio (e.g. cc2420).
* Introduces a new way to configure the network stack. Four #defines
that specify what mechanism/protocol/driver to use at the four
layers: NETSTACK_CONF_NETWORK, NETSTACK_CONF_MAC, NETSTACK_CONF_RDC,
NETSTACK_CONF_RADIO.
* Adds a callback mechanism to inform the MAC and network layers about
the fate of a transmitted packet: if the packet was not possible to
transmit, the cause of the failure is reported, and if the packets
was successfully transmitted, the number of tries before it was
finally transmitted is reported.
* NULL-protocols at both the MAC and RDC layers: nullmac and nullrdc,
which can be used when MAC and RDC functionality is not needed.
* Extends the radio API with three new functions that enable more
efficient radio duty cycling protocols: channel check, pending
packet, and receiving packet.
* New initialization mechanism, which takes advantage of the NETSTACK
#defines.
2010-02-18 22:48:39 +01:00
|
|
|
input_packet,
|
2010-01-25 12:46:44 +01:00
|
|
|
on,
|
|
|
|
off,
|
|
|
|
channel_check_interval,
|
|
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*/
|