43 #include "lib/random.h" 47 #define LOG_MODULE "Frame 15.4" 48 #define LOG_LEVEL LOG_LEVEL_FRAMER 56 static uint8_t initialized = 0;
60 create_frame(
int do_create)
65 if(frame802154_get_pan_id() == 0xffff) {
70 memset(¶ms, 0,
sizeof(params));
84 if(do_create != 0 && packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO) == 0) {
88 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO,
mac_dsn);
100 packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
104 packetbuf_addr(PACKETBUF_ADDR_SENDER));
116 LOG_INFO_LLADDR((
const linkaddr_t *)params.
dest_addr);
121 LOG_ERR(
"Out: too large header: %u\n", hdr_len);
122 return FRAMER_FAILED;
127 framer_802154_setup_params(packetbuf_attr_t (*get_attr)(uint8_t type),
130 if(get_attr == NULL || params == NULL) {
131 LOG_INFO(
"framer-802154: cannot setup params because of invalid argument\n");
141 params->
fcf.
frame_type = get_attr(PACKETBUF_ATTR_FRAME_TYPE);
143 if(dest_is_broadcast) {
158 #if LLSEC802154_USES_AUX_HEADER 159 if(get_attr(PACKETBUF_ATTR_SECURITY_LEVEL)) {
164 #if LLSEC802154_USES_FRAME_COUNTER 171 #if LLSEC802154_USES_EXPLICIT_KEYS 179 params->
seq = get_attr(PACKETBUF_ATTR_MAC_SEQNO);
182 params->
src_pid = frame802154_get_pan_id();
185 if(get_attr(PACKETBUF_ATTR_MAC_NO_SRC_ADDR) == 1) {
188 if(LINKADDR_SIZE == 2) {
196 params->
dest_pid = frame802154_get_pan_id();
199 if(get_attr(PACKETBUF_ATTR_MAC_NO_DEST_ADDR) == 1) {
201 }
else if(dest_is_broadcast) {
205 if(LINKADDR_SIZE == 2) {
224 return create_frame(0);
230 return create_frame(1);
242 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, frame.
fcf.
frame_type);
245 if(frame.
dest_pid != frame802154_get_pan_id() &&
246 frame.
dest_pid != FRAME802154_BROADCASTPANDID) {
248 LOG_WARN(
"15.4: for another pan %u\n", frame.
dest_pid);
249 return FRAMER_FAILED;
252 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.
dest_addr);
255 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.
src_addr);
257 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.
seq);
259 packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, 0xffff);
261 #if NETSTACK_CONF_WITH_RIME 262 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.
seq);
265 #if LLSEC802154_USES_AUX_HEADER 268 #if LLSEC802154_USES_FRAME_COUNTER 272 #if LLSEC802154_USES_EXPLICIT_KEYS 280 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
282 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
287 return FRAMER_FAILED;
290 const struct framer framer_802154 = {
frame802154_frame_counter_t frame_counter
Frame counter, used for security.
uint16_t src_pid
Source PAN ID.
frame802154_scf_t security_control
Security control bitfield.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
uint8_t dest_addr_mode
2 bit.
uint8_t sequence_number_suppression
< 1 bit.
frame802154_fcf_t fcf
Frame control field.
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
#define FRAME802154_NOADDR
Only valid for ACK or Beacon frames.
uint8_t security_level
3 bit.
uint8_t security_enabled
1 bit.
int packetbuf_hdrreduce(int size)
Reduce the header in the packetbuf, for incoming packets.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
int payload_len
Length of payload field.
Common functionality of 802.15.4-compliant llsec_drivers.
uint8_t frame_pending
1 bit.
uint8_t src_addr[8]
Source address.
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
A MAC framer for IEEE 802.15.4
uint8_t key_id_mode
2 bit.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
uint8_t key_index
Key Index subfield.
uint8_t frame_counter_suppression
1 bit.
uint8_t frame_version
2 bit.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
static uint8_t mac_dsn
The sequence number (0x00 - 0xff) added to the transmitted data or MAC command frame.
uint8_t src_addr_mode
2 bit.
802.15.4 frame creation and parsing functions
int packetbuf_holds_broadcast(void)
Checks whether the current packet is a broadcast.
uint16_t dest_pid
Destination PAN ID.
Parameters used by the frame802154_create() function.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
uint8_t ie_list_present
1 bit.
uint8_t seq
Sequence number.
uint8_t panid_compression
1 bit.
Header file for the Packet buffer (packetbuf) management
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
uint8_t * payload
Pointer to 802.15.4 payload.
uint8_t dest_addr[8]
Destination address.
Header file for the logging system
uint8_t ack_required
1 bit.
uint8_t frame_counter_size
1 bit.
frame802154_aux_hdr_t aux_hdr
Aux security header.
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.