44#include "packetutils.h"
51#define LOG_MODULE "BR-MAC"
52#define LOG_LEVEL LOG_LEVEL_NONE
54#define MAX_CALLBACKS 16
55static int callback_pos;
62 struct packetbuf_attr attrs[PACKETBUF_NUM_ATTRS];
63 struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
66static struct tx_callback callbacks[MAX_CALLBACKS];
72#if LLSEC802154_USES_AUX_HEADER
73 if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) ==
74 PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT) {
75 packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL,
76 CSMA_LLSEC_SECURITY_LEVEL);
83packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
85 if(sessionid < MAX_CALLBACKS) {
86 struct tx_callback *callback;
87 callback = &callbacks[sessionid];
89 packetbuf_attr_copyfrom(callback->attrs, callback->addrs);
90 mac_call_sent_callback(callback->cback, callback->ptr, status, tx);
92 LOG_ERR(
"Session id to high (%d)\n", sessionid);
97setup_callback(mac_callback_t sent,
void *ptr)
99 struct tx_callback *callback;
100 int tmp = callback_pos;
101 callback = &callbacks[callback_pos];
102 callback->cback = sent;
104 packetbuf_attr_copyto(callback->attrs, callback->addrs);
107 if(callback_pos >= MAX_CALLBACKS) {
125 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
128 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
135 if(NETSTACK_FRAMER.create() < 0) {
137 LOG_WARN(
"send failed, too large header\n");
142#if SERIALIZE_ATTRIBUTES
143 size = packetutils_serialize_atts(&buf[3],
sizeof(buf) - 3);
146 LOG_WARN(
"send failed, too large header\n");
149 sid = setup_callback(sent, ptr);
166 if(NETSTACK_FRAMER.parse() < 0) {
169 NETSTACK_NETWORK.input();
189 return 127 - NETSTACK_FRAMER.length();
199const struct mac_driver border_router_mac_driver = {
Border router header file.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void packetbuf_clear(void)
Clear and reset the packetbuf.
static void send_packet(void)
This function is called by the 6lowpan code to send out a packet.
static void packet_sent(void *ptr, int status, int transmissions)
Callback function for the MAC packet sent callback.
Header file for the logging system.
void mac_sequence_set_dsn(void)
Sets and increments the destination sequence number.
void mac_sequence_init(void)
brief Initializes the destination sequence number to a random value.
Header file for MAC sequence numbers management.
@ MAC_TX_ERR_FATAL
The MAC layer transmission could not be performed because of insufficient queue space,...
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet buffer (packetbuf) management.
Header file for the Packet queue buffer management.
The structure of a MAC protocol driver in Contiki.
int(* on)(void)
Turn the MAC layer on.
int(* max_payload)(void)
Read out estimated max payload size based on payload in packetbuf.
int(* off)(void)
Turn the MAC layer off.
void(* init)(void)
Initialize the MAC driver.