A Carrier Sense Multiple Access (CSMA) MAC layer
#include "net/mac/csma.h"
#include "net/packetbuf.h"
#include "net/queuebuf.h"
#include "sys/ctimer.h"
#include "sys/contiki-clock.h"
#include "lib/random.h"
#include "net/netstack.h"
#include "lib/list.h"
#include "lib/memb.h"
#include <string.h>
#include <stdio.h>
Data Structures | |
struct | neighbor_queue |
struct | qbuf_metadata |
Macros | |
#define | _DEBUG_ 0 |
#define | CSMA_MAX_BACKOFF_EXPONENT 3 |
#define | CSMA_MAX_MAC_TRANSMISSIONS 3 |
#define | CSMA_MAX_NEIGHBOR_QUEUES 4 |
#define | MAX_QUEUED_PACKETS QUEUEBUF_NUM |
#define | PRINTF(...) |
Functions | |
static unsigned short | channel_check_interval (void) |
static clock_time_t | default_timebase (void) |
static void | free_packet (struct neighbor_queue *n, struct rdc_buf_list *p) |
static void | init (void) |
static void | input_packet (void) |
LIST (neighbor_list) | |
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) | |
static struct neighbor_queue * | neighbor_queue_from_addr (const linkaddr_t *addr) |
static int | off (int keep_radio_on) |
static int | on (void) |
static void | packet_sent (void *ptr, int status, int num_transmissions) |
static void | send_packet (mac_callback_t sent, void *ptr) |
static void | transmit_packet_list (void *ptr) |
Variables | |
struct mac_driver | csma_driver |
#define _DEBUG_ 0 |
#define CSMA_MAX_BACKOFF_EXPONENT 3 |
Referenced by packet_sent().
#define CSMA_MAX_MAC_TRANSMISSIONS 3 |
Referenced by send_packet().
#define CSMA_MAX_NEIGHBOR_QUEUES 4 |
#define MAX_QUEUED_PACKETS QUEUEBUF_NUM |
#define PRINTF | ( | ... | ) |
Referenced by free_packet(), packet_sent(), send_packet(), and transmit_packet_list().
|
static |
References rdc_driver::channel_check_interval, and NETSTACK_RDC.
|
static |
References rdc_driver::channel_check_interval, CLOCK_SECOND, NETSTACK_RDC, and NETSTACK_RDC_CHANNEL_CHECK_RATE.
Referenced by free_packet(), and packet_sent().
|
static |
References rdc_buf_list::buf, neighbor_queue::collisions, ctimer_set(), ctimer_stop(), default_timebase(), neighbor_queue::deferrals, list_head(), list_length(), list_remove(), memb_free(), NULL, PRINTF, rdc_buf_list::ptr, queuebuf_free(), neighbor_queue::transmissions, transmit_packet_list(), and neighbor_queue::transmit_timer.
Referenced by packet_sent().
|
static |
References memb_init().
|
static |
References network_driver::input, and NETSTACK_NETWORK.
LIST | ( | neighbor_list | ) |
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 | |||
) |
|
static |
References neighbor_queue::addr, linkaddr_cmp(), list_head(), list_item_next(), n, and NULL.
Referenced by send_packet().
|
static |
References NETSTACK_RDC, and rdc_driver::off.
|
static |
References NETSTACK_RDC, and rdc_driver::on.
|
static |
References rdc_buf_list::buf, neighbor_queue::collisions, qbuf_metadata::cptr, CSMA_MAX_BACKOFF_EXPONENT, ctimer_set(), default_timebase(), neighbor_queue::deferrals, free_packet(), list_head(), list_item_next(), mac_call_sent_callback(), MAC_TX_AGAIN, MAC_TX_COLLISION, MAC_TX_DEFERRED, MAC_TX_NOACK, MAC_TX_OK, qbuf_metadata::max_transmissions, metadata, n, NULL, PACKETBUF_ATTR_MAC_SEQNO, PRINTF, rdc_buf_list::ptr, ptr, queuebuf_attr(), queuebuf_update_attr_from_packetbuf(), random_rand(), qbuf_metadata::sent, neighbor_queue::transmissions, transmit_packet_list(), and neighbor_queue::transmit_timer.
Referenced by transmit_packet_list().
|
static |
References neighbor_queue::addr, addr, rdc_buf_list::buf, neighbor_queue::collisions, qbuf_metadata::cptr, CSMA_MAX_MAC_TRANSMISSIONS, ctimer_set(), neighbor_queue::deferrals, initialized, linkaddr_copy(), list_add(), list_head(), list_length(), list_push(), list_remove(), LIST_STRUCT_INIT, mac_call_sent_callback(), MAC_TX_ERR, qbuf_metadata::max_transmissions, memb_alloc(), memb_free(), metadata, n, neighbor_queue_from_addr(), NULL, packetbuf_addr(), PACKETBUF_ADDR_RECEIVER, packetbuf_attr(), PACKETBUF_ATTR_MAC_SEQNO, PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_ACK, packetbuf_set_attr(), PRINTF, rdc_buf_list::ptr, ptr, queuebuf_new_from_packetbuf(), random_rand(), qbuf_metadata::sent, neighbor_queue::transmissions, transmit_packet_list(), and neighbor_queue::transmit_timer.
|
static |
References list_head(), list_length(), n, NETSTACK_RDC, NULL, packet_sent(), PRINTF, ptr, rdc_driver::send_list, and neighbor_queue::transmissions.
Referenced by free_packet(), packet_sent(), and send_packet().
struct mac_driver csma_driver |