43 #include "packetutils.h" 50 #define LOG_MODULE "BR-MAC" 51 #define LOG_LEVEL LOG_LEVEL_NONE 53 #define MAX_CALLBACKS 16 54 static int callback_pos;
61 struct packetbuf_attr attrs[PACKETBUF_NUM_ATTRS];
62 struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
65 static 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);
82 packet_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);
96 setup_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");
134 mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
138 #if SERIALIZE_ATTRIBUTES 139 size = packetutils_serialize_atts(&buf[3],
sizeof(buf) - 3);
142 LOG_WARN(
"send failed, too large header\n");
143 mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
145 sid = setup_callback(sent, ptr);
162 if(NETSTACK_FRAMER.parse() < 0) {
165 NETSTACK_NETWORK.input();
185 return 127 - NETSTACK_FRAMER.length();
194 const struct mac_driver border_router_mac_driver = {
int(* on)(void)
Turn the MAC layer on.
void packetbuf_clear(void)
Clear and reset the packetbuf.
Border router header file
The structure of a MAC protocol driver in Contiki.
static void send_packet(linkaddr_t *dest)
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.
int(* off)(void)
Turn the MAC layer off.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
Header file for the Packet queue buffer management
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
void(* init)(void)
Initialize the MAC driver.
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
int(* max_payload)(void)
Read out estimated max payload size based on payload in packetbuf.
Header file for the logging system