52 #include "lib/random.h"
58 #define PRINTF(...) printf(__VA_ARGS__)
59 #define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7])
62 #define PRINTADDR(addr)
69 static uint8_t mac_dsn;
75 static uint16_t mac_dst_pan_id = IEEE802154_PANID;
81 static uint16_t mac_src_pan_id = IEEE802154_PANID;
85 is_broadcast_addr(uint8_t mode, uint8_t *addr)
87 int i = mode == FRAME802154_SHORTADDRMODE ? 2 : 8;
97 send_packet(mac_callback_t sent,
void *ptr)
103 memset(¶ms, 0,
sizeof(params));
116 params.
seq = mac_dsn++;
138 packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
143 params.
src_pid = mac_src_pan_id;
149 #if NETSTACK_CONF_BRIDGE_MODE
178 PRINTF(
"6MAC-UT: too large header: %u\n", len);
183 send_list(mac_callback_t sent,
void *ptr,
struct rdc_buf_list *buf_list)
185 if(buf_list !=
NULL) {
186 queuebuf_to_packetbuf(buf_list->buf);
187 send_packet(sent, ptr);
202 if(frame.
dest_pid != mac_src_pan_id &&
203 frame.
dest_pid != FRAME802154_BROADCASTPANDID) {
205 PRINTF(
"6MAC: for another pan %u\n", frame.
dest_pid);
209 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.
dest_addr);
210 #if !NETSTACK_CONF_BRIDGE_MODE
211 if(!
linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
214 PRINTF(
"6MAC: not for us\n");
220 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.
src_addr);
223 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
224 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
226 NETSTACK_MAC.input();
228 PRINTF(
"6MAC: failed to parse hdr\n");
235 return NETSTACK_RADIO.on();
239 off(
int keep_radio_on)
242 return NETSTACK_RADIO.on();
244 return NETSTACK_RADIO.off();
256 static unsigned short
257 channel_check_interval(
void)
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
uint8_t * payload
Pointer to 802.15.4 payload.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
802.15.4 frame creation and parsing functions
uint8_t ack_required
1 bit.
uint8_t frame_version
2 bit.
const linkaddr_t linkaddr_null
The null Rime address.
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
Header file for the Rime buffer (packetbuf) management
uint8_t security_enabled
1 bit.
#define NULL
The null pointer.
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.
The MAC layer transmission could not be performed because of a fatal error.
uint8_t src_addr_mode
2 bit.
uint8_t panid_compression
1 bit.
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.
MAC interface for packaging radio packets into 802.15.4 frames
Parameters used by the frame802154_create() function.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
uint8_t seq
Sequence number.
int payload_len
Length of payload field.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
int(* off)(int keep_radio_on)
Turn the MAC layer off.
Header file for the Rime queue buffer management
uint8_t dest_addr[8]
Destination address.
unsigned short(* channel_check_interval)(void)
Returns the channel check interval, expressed in clock_time_t ticks.
The structure of a RDC (radio duty cycling) driver in Contiki.
uint16_t dest_pid
Destination PAN ID.
void(* init)(void)
Initialize the RDC driver.
uint16_t src_pid
Source PAN ID.
The MAC layer transmission was OK.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
int(* on)(void)
Turn the MAC layer on.
uint8_t frame_pending
1 bit.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
frame802154_fcf_t fcf
Frame control field.
unsigned short random_rand(void)
Generate the next state and return the upper part of it.
int packetbuf_hdrreduce(int size)
Reduce the header in the packetbuf, for incoming packets.
void(* send_list)(mac_callback_t sent_callback, void *ptr, struct rdc_buf_list *list)
Send a packet list.
uint8_t src_addr[8]
Source address.
Include file for the Contiki low-layer network stack (NETSTACK)
uint8_t dest_addr_mode
< 3 bit.