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);
77 #if CSMA_SEND_SOFT_ACK 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");
156 LOG_WARN(
"radio does not support setting RADIO_PARAM_RX_MODE\n");
162 #if LLSEC802154_USES_AUX_HEADER 163 #ifdef CSMA_LLSEC_DEFAULT_KEY0 164 uint8_t key[16] = CSMA_LLSEC_DEFAULT_KEY0;
165 csma_security_set_key(0, key);
181 framer_hdrlen = NETSTACK_FRAMER.length();
183 res = NETSTACK_RADIO.get_value(RADIO_CONST_MAX_PAYLOAD_LEN,
184 &max_radio_payload_len);
187 LOG_ERR(
"Failed to retrieve max radio driver payload length\n");
191 if(framer_hdrlen < 0) {
193 framer_hdrlen = CSMA_MAC_MAX_HEADER;
198 - LLSEC802154_PACKETBUF_MIC_LEN();
The parameter is not supported.
int(* on)(void)
Turn the MAC layer on.
The 802.15.4 standard CSMA protocol (nonbeacon-enabled).
The structure of a MAC protocol driver in Contiki.
The 802.15.4 standard CSMA protocol (nonbeacon-enabled)
static void send_packet(linkaddr_t *dest)
This function is called by the 6lowpan code to send out a packet.
int mac_sequence_is_duplicate(void)
Tell whether the packetbuf is a duplicate packet.
The parameter was set/read successfully.
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
Header file for MAC sequence numbers management
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.
Radio receiver mode determines if the radio has address filter (RADIO_RX_MODE_ADDRESS_FILTER) and aut...
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
int 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 linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
#define RADIO_RX_MODE_AUTOACK
Enable automatic transmission of ACK frames.
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)
void mac_sequence_register_seqno(void)
Register the sequence number of the packetbuf.
int(* max_payload)(void)
Read out estimated max payload size based on payload in packetbuf.
Header file for the logging system