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];
68 packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx)
70 if(sessionid < MAX_CALLBACKS) {
71 struct tx_callback *callback;
72 callback = &callbacks[sessionid];
74 packetbuf_attr_copyfrom(callback->attrs, callback->addrs);
75 mac_call_sent_callback(callback->cback, callback->ptr, status, tx);
77 LOG_ERR(
"Session id to high (%d)\n", sessionid);
82 setup_callback(mac_callback_t sent,
void *ptr)
84 struct tx_callback *callback;
85 int tmp = callback_pos;
86 callback = &callbacks[callback_pos];
87 callback->cback = sent;
89 packetbuf_attr_copyto(callback->attrs, callback->addrs);
92 if(callback_pos >= MAX_CALLBACKS) {
110 packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
113 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME);
117 if(NETSTACK_FRAMER.create() < 0) {
119 LOG_WARN(
"send failed, too large header\n");
120 mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
124 #if SERIALIZE_ATTRIBUTES 125 size = packetutils_serialize_atts(&buf[3],
sizeof(buf) - 3);
128 LOG_WARN(
"send failed, too large header\n");
129 mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
131 sid = setup_callback(sent, ptr);
148 if(NETSTACK_FRAMER.parse() < 0) {
151 NETSTACK_NETWORK.input();
173 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)
Header file for the logging system