43 #include "lib/random.h"
50 #define PRINTF(...) printf(__VA_ARGS__)
51 #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])
54 #define PRINTADDR(addr)
63 static uint8_t initialized = 0;
72 if(frame802154_get_pan_id() == 0xffff) {
77 memset(¶ms, 0,
sizeof(params));
85 params.
fcf.
frame_type = packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE);
101 #if LLSEC802154_USES_AUX_HEADER
102 if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL)) {
107 #if LLSEC802154_USES_FRAME_COUNTER
114 #if LLSEC802154_USES_EXPLICIT_KEYS
117 params.
aux_hdr.
key_source.u16[0] = packetbuf_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1);
126 }
else if(packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO)) {
127 params.
seq = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO);
135 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, params.
seq);
143 if(LINKADDR_SIZE == 2) {
149 params.
dest_pid = frame802154_get_pan_id();
158 packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
160 if(LINKADDR_SIZE == 2) {
168 params.
src_pid = frame802154_get_pan_id();
191 PRINTF(
"15.4-OUT: too large header: %u\n", hdr_len);
192 return FRAMER_FAILED;
217 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, frame.
fcf.
frame_type);
220 if(frame.
dest_pid != frame802154_get_pan_id() &&
221 frame.
dest_pid != FRAME802154_BROADCASTPANDID) {
223 PRINTF(
"15.4: for another pan %u\n", frame.
dest_pid);
224 return FRAMER_FAILED;
227 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.
dest_addr);
230 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.
src_addr);
233 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.
seq);
235 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, 0xffff);
237 #if NETSTACK_CONF_WITH_RIME
238 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.
seq);
241 #if LLSEC802154_USES_AUX_HEADER
244 #if LLSEC802154_USES_FRAME_COUNTER
248 #if LLSEC802154_USES_EXPLICIT_KEYS
251 packetbuf_set_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1, frame.
aux_hdr.
key_source.u16[0]);
257 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
258 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
263 return FRAMER_FAILED;
266 const struct framer framer_802154 = {
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
uint8_t security_enabled
1 bit.
uint16_t src_pid
Source PAN ID.
frame802154_scf_t security_control
Security control bitfield.
uint8_t dest_addr[8]
Destination address.
uint8_t key_id_mode
2 bit.
uint16_t dest_pid
Destination PAN ID.
uint8_t key_index
Key Index subfield.
frame802154_fcf_t fcf
Frame control field.
frame802154_frame_counter_t frame_counter
Frame counter, used for security.
int payload_len
Length of payload field.
uint8_t frame_pending
1 bit.
uint8_t src_addr[8]
Source address.
uint8_t seq
Sequence number.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
uint8_t * payload
Pointer to 802.15.4 payload.
Common functionality of 802.15.4-compliant llsec_drivers.
int packetbuf_holds_broadcast(void)
Checks whether the current packet is a broadcast.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
Header file for the Rime buffer (packetbuf) management
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.
frame802154_key_source_t key_source
Key Source subfield.
802.15.4 frame creation and parsing functions
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
uint8_t security_level
3 bit.
uint8_t src_addr_mode
2 bit.
uint8_t frame_counter_size
1 bit.
frame802154_aux_hdr_t aux_hdr
Aux security header.
uint8_t dest_addr_mode
2 bit.
static uint8_t mac_dsn
The sequence number (0x00 - 0xff) added to the transmitted data or MAC command frame.
uint8_t panid_compression
1 bit.
uint8_t ack_required
1 bit.
static int create_frame(int type, int do_create)
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
uint8_t frame_version
2 bit.
int packetbuf_hdrreduce(int size)
Reduce the header in the packetbuf, for incoming packets.
Parameters used by the frame802154_create() function.
uint8_t frame_counter_suppression
1 bit.
A MAC framer for IEEE 802.15.4
uint8_t sequence_number_suppression
< 1 bit.