49#define LOG_MODULE "CSMA"
50#define LOG_LEVEL LOG_LEVEL_MAC
56#if LLSEC802154_USES_AUX_HEADER
57 if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) ==
58 PACKETBUF_ATTR_SECURITY_LEVEL_DEFAULT) {
59 packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL,
60 CSMA_LLSEC_SECURITY_LEVEL);
71 csma_output_packet(sent, ptr);
78 uint8_t ackdata[CSMA_ACK_LEN];
83 LOG_DBG(
"ignored ack\n");
84 }
else if(csma_security_parse_frame() < 0) {
86 }
else if(!
linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
89 LOG_WARN(
"not for us\n");
91 LOG_WARN(
"frame from ourselves\n");
99 LOG_WARN(
"drop duplicate link layer packet from ");
100 LOG_WARN_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
101 LOG_WARN_(
", seqno %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO));
106#if CSMA_SEND_SOFT_ACK
107 if(packetbuf_attr(PACKETBUF_ATTR_MAC_ACK)) {
108 ackdata[0] = FRAME802154_ACKFRAME;
111 NETSTACK_RADIO.send(ackdata, CSMA_ACK_LEN);
115 LOG_INFO(
"received packet from ");
116 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
117 LOG_INFO_(
", seqno %u, len %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO),
packetbuf_datalen());
118 NETSTACK_NETWORK.input();
126 return NETSTACK_RADIO.on();
132 return NETSTACK_RADIO.off();
141 if(NETSTACK_RADIO.get_value(RADIO_CONST_MAX_PAYLOAD_LEN, &radio_max_payload_len) !=
RADIO_RESULT_OK) {
142 LOG_ERR(
"! radio does not support getting RADIO_CONST_MAX_PAYLOAD_LEN. Abort init.\n");
146#if CSMA_SEND_SOFT_ACK
151 LOG_WARN(
"radio does not support getting RADIO_PARAM_RX_MODE\n");
154 radio_rx_mode &= ~RADIO_RX_MODE_AUTOACK;
156 LOG_WARN(
"radio does not support setting RADIO_PARAM_RX_MODE\n");
163#if LLSEC802154_USES_AUX_HEADER
164#ifdef CSMA_LLSEC_DEFAULT_KEY0
165 uint8_t key[16] = CSMA_LLSEC_DEFAULT_KEY0;
166 csma_security_set_key(0, key);
182 framer_hdrlen = NETSTACK_FRAMER.length();
184 res = NETSTACK_RADIO.get_value(RADIO_CONST_MAX_PAYLOAD_LEN,
185 &max_radio_payload_len);
188 LOG_ERR(
"Failed to retrieve max radio driver payload length\n");
192 if(framer_hdrlen < 0) {
194 framer_hdrlen = CSMA_MAC_MAX_HEADER;
199 - LLSEC802154_PACKETBUF_MIC_LEN();
The 802.15.4 standard CSMA protocol (nonbeacon-enabled).
The 802.15.4 standard CSMA protocol (nonbeacon-enabled)
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
bool linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
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.
bool packetbuf_holds_broadcast(void)
Checks whether the current packet is a broadcast.
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio.
@ RADIO_RESULT_NOT_SUPPORTED
The parameter is not supported.
@ RADIO_RESULT_OK
The parameter was set/read successfully.
@ RADIO_PARAM_RX_MODE
Radio receiver mode determines if the radio has address filter (RADIO_RX_MODE_ADDRESS_FILTER) and aut...
static void send_packet(void)
This function is called by the 6lowpan code to send out a packet.
Header file for the logging system.
int mac_sequence_is_duplicate(void)
Tell whether the packetbuf is a duplicate packet.
void mac_sequence_register_seqno(void)
Register the sequence number of the packetbuf.
void mac_sequence_init(void)
brief Initializes the destination sequence number to a random value.
Header file for MAC sequence numbers management.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Packet buffer (packetbuf) 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.