43#include "packetutils.h"
50#define LOG_MODULE "BR-MAC"
51#define LOG_LEVEL LOG_LEVEL_NONE
53#define MAX_CALLBACKS 16
54static int callback_pos;
61 struct packetbuf_attr attrs[PACKETBUF_NUM_ATTRS];
62 struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
65static struct tx_callback callbacks[MAX_CALLBACKS];
71#if LLSEC802154_USES_AUX_HEADER
72 if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) ==
73 PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT) {
74 packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL,
75 CSMA_LLSEC_SECURITY_LEVEL);
82packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
84 if(sessionid < MAX_CALLBACKS) {
85 struct tx_callback *callback;
86 callback = &callbacks[sessionid];
88 packetbuf_attr_copyfrom(callback->attrs, callback->addrs);
89 mac_call_sent_callback(callback->cback, callback->ptr, status, tx);
91 LOG_ERR(
"Session id to high (%d)\n", sessionid);
96setup_callback(mac_callback_t sent,
void *ptr)
98 struct tx_callback *callback;
99 int tmp = callback_pos;
100 callback = &callbacks[callback_pos];
101 callback->cback = sent;
103 packetbuf_attr_copyto(callback->attrs, callback->addrs);
106 if(callback_pos >= MAX_CALLBACKS) {
124 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
127 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
131 if(NETSTACK_FRAMER.create() < 0) {
133 LOG_WARN(
"send failed, too large header\n");
138#if SERIALIZE_ATTRIBUTES
139 size = packetutils_serialize_atts(&buf[3],
sizeof(buf) - 3);
142 LOG_WARN(
"send failed, too large header\n");
145 sid = setup_callback(sent, ptr);
162 if(NETSTACK_FRAMER.parse() < 0) {
165 NETSTACK_NETWORK.input();
185 return 127 - NETSTACK_FRAMER.length();
194const 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 packet_sent(void *ptr, int status, int transmissions)
Callback function for the MAC packet sent callback.
static void send_packet(linkaddr_t *dest)
This function is called by the 6lowpan code to send out a packet.
Header file for the logging system.
@ 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.