The friendly Operating System for the Internet of Things
IEEE802.15.4

IEEE802.15.4 header definitions and utility functions. More...

Detailed Description

Files

file  sys/include/net/ieee802154.h
 IEEE 802.15.4 header definitions.
 

Macros

#define IEEE802154_FRAME_LEN_MAX   (127U)
 maximum frame length
 

Functions

size_t ieee802154_set_frame_hdr (uint8_t *buf, const uint8_t *src, size_t src_len, const uint8_t *dst, size_t dst_len, le_uint16_t src_pan, le_uint16_t dst_pan, uint8_t flags, uint8_t seq)
 Initializes an IEEE 802.15.4 MAC frame header in buf. More...
 
size_t ieee802154_get_frame_hdr_len (const uint8_t *mhr)
 Get length of MAC header. More...
 
int ieee802154_get_src (const uint8_t *mhr, uint8_t *src, le_uint16_t *src_pan)
 Gets source address from MAC header. More...
 
int ieee802154_get_dst (const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan)
 Gets destination address from MAC header. More...
 
static uint8_t ieee802154_get_seq (const uint8_t *mhr)
 Gets sequence number from MAC header. More...
 
static eui64_tieee802154_get_iid (eui64_t *eui64, const uint8_t *addr, size_t addr_len)
 Generates an IPv6 interface identifier from an IEEE 802.15.4 address. More...
 
#define IEEE802154_SHORT_ADDRESS_LEN   (2U)
 IEEE 802.15.4 address lengths. More...
 
#define IEEE802154_LONG_ADDRESS_LEN   (8U)
 long address (EUI-64)
 
#define IEEE802154_MAX_HDR_LEN   (23U)
 IEEE802.15.4 FCF field definitions.
 
#define IEEE802154_FCF_LEN   (2U)
 
#define IEEE802154_FCS_LEN   (2U)
 
#define IEEE802154_FCF_TYPE_MASK   (0x07)
 
#define IEEE802154_FCF_TYPE_BEACON   (0x00)
 
#define IEEE802154_FCF_TYPE_DATA   (0x01)
 
#define IEEE802154_FCF_TYPE_ACK   (0x02)
 
#define IEEE802154_FCF_TYPE_MACCMD   (0x03)
 
#define IEEE802154_FCF_SECURITY_EN   (0x08)
 enable security
 
#define IEEE802154_FCF_FRAME_PEND   (0x10)
 follow-up frame is pending
 
#define IEEE802154_FCF_ACK_REQ   (0x20)
 acknowledgement requested from receiver
 
#define IEEE802154_FCF_PAN_COMP   (0x40)
 compress source PAN ID
 
#define IEEE802154_FCF_DST_ADDR_MASK   (0x0c)
 
#define IEEE802154_FCF_DST_ADDR_VOID   (0x00)
 no destination address
 
#define IEEE802154_FCF_DST_ADDR_RESV   (0x04)
 reserved address mode
 
#define IEEE802154_FCF_DST_ADDR_SHORT   (0x08)
 destination address length is 2
 
#define IEEE802154_FCF_DST_ADDR_LONG   (0x0c)
 destination address length is 8
 
#define IEEE802154_FCF_VERS_MASK   (0x30)
 
#define IEEE802154_FCF_VERS_V0   (0x00)
 
#define IEEE802154_FCF_VERS_V1   (0x10)
 
#define IEEE802154_FCF_SRC_ADDR_MASK   (0xc0)
 
#define IEEE802154_FCF_SRC_ADDR_VOID   (0x00)
 no source address
 
#define IEEE802154_FCF_SRC_ADDR_RESV   (0x40)
 reserved address mode
 
#define IEEE802154_FCF_SRC_ADDR_SHORT   (0x80)
 source address length is 2
 
#define IEEE802154_FCF_SRC_ADDR_LONG   (0xc0)
 source address length is 8
 
#define IEEE802154_CHANNEL_MIN_SUBGHZ   (0U)
 Channel ranges. More...
 
#define IEEE802154_CHANNEL_MAX_SUBGHZ   (10U)
 Maximum channel for sub-GHz band.
 
#define IEEE802154_CHANNEL_MIN   (11U)
 Minimum channel for 2.4 GHz band.
 
#define IEEE802154_CHANNEL_MAX   (26U)
 Maximum channel for 2.4 GHz band.
 
const uint8_t ieee802154_addr_bcast [IEEE802154_ADDR_BCAST_LEN]
 Broadcast address.
 
#define IEEE802154_ADDR_BCAST   { 0xff, 0xff }
 Special address defintions. More...
 
#define IEEE802154_ADDR_BCAST_LEN   (IEEE802154_SHORT_ADDRESS_LEN)
 Length in byte of IEEE802154_ADDR_BCAST.
 

Default values

Default values for devices to choose

#define IEEE802154_DEFAULT_SUBGHZ_CHANNEL   (5U)
 
#define IEEE802154_DEFAULT_CHANNEL   (26U)
 
#define IEEE802154_DEFAULT_PANID   (0x0023U)
 
#define IEEE802154_DEFAULT_TXPOWER   (0) /* in dBm */
 

Macro Definition Documentation

#define IEEE802154_ADDR_BCAST   { 0xff, 0xff }

Static initializer for broadcast address

Definition at line 99 of file sys/include/net/ieee802154.h.

#define IEEE802154_CHANNEL_MIN_SUBGHZ   (0U)

Minimum channel for sub-GHz band

Definition at line 84 of file sys/include/net/ieee802154.h.

#define IEEE802154_SHORT_ADDRESS_LEN   (2U)

short (16-bit) address

Definition at line 38 of file sys/include/net/ieee802154.h.

Function Documentation

int ieee802154_get_dst ( const uint8_t *  mhr,
uint8_t *  dst,
le_uint16_t dst_pan 
)
Precondition
(dst != NULL) && (dst_pan != NULL)
Parameters
[in]mhrMAC header.
[out]dstDestination address in network byte order in MAC header.
[out]dst_panDestination PAN in little-endian byte order in MAC header.
Returns
Length of destination address.
-EINVAL, if mhr contains unexpected flags.
size_t ieee802154_get_frame_hdr_len ( const uint8_t *  mhr)
Todo:
include security header implications
Parameters
[in]mhrMAC header.
Returns
Length of MAC header on success.
0, on error (source mode or destination mode set to reserved).
static eui64_t* ieee802154_get_iid ( eui64_t eui64,
const uint8_t *  addr,
size_t  addr_len 
)
inlinestatic
Precondition
(eui64 != NULL) && (addr != NULL)
See also
RFC 4944, section 6
RFC 6282, section 3.2.2
Parameters
[out]eui64The resulting EUI-64.
[in]addrAn IEEE 802.15.4 address.
[in]addr_lenThe length of addr. Must be 2 (short address), 4 (PAN ID + short address), or 8 (long address).
Returns
Copy of eui64 on success.
NULL, if addr_len was of illegal length.

Definition at line 255 of file sys/include/net/ieee802154.h.

static uint8_t ieee802154_get_seq ( const uint8_t *  mhr)
inlinestatic
Precondition
length of allocated space at mhr > 3
Parameters
[in]mhrMAC header.
Returns
The sequence number in mhr.

Definition at line 231 of file sys/include/net/ieee802154.h.

int ieee802154_get_src ( const uint8_t *  mhr,
uint8_t *  src,
le_uint16_t src_pan 
)
Precondition
(src != NULL) && (src_pan != NULL)
Parameters
[in]mhrMAC header.
[out]srcSource address in network byte order in MAC header.
[out]src_panSource PAN little-endian byte order in MAC header.
Returns
Length of source address.
-EINVAL, if mhr contains unexpected flags.
size_t ieee802154_set_frame_hdr ( uint8_t *  buf,
const uint8_t *  src,
size_t  src_len,
const uint8_t *  dst,
size_t  dst_len,
le_uint16_t  src_pan,
le_uint16_t  dst_pan,
uint8_t  flags,
uint8_t  seq 
)
Precondition
Resulting header must fit in memory allocated at buf.
See also
IEEE Std 802.15.4-2011, 5.2.1 General MAC frame format.

If dst is NULL the IEEE802154_FCF_ACK_REQ will be unset to prevent flooding the network.

Parameters
[out]bufTarget memory for frame header.
[in]srcSource address for frame in network byteorder. May be NULL if IEEE802154_FCF_SRC_ADDR_VOID is set in flags.
[in]src_lenLength of src. Legal values are:
[in]dstDestination address for frame in network byteorder. May be NULL if IEEE802154_FCF_SRC_ADDR_VOID is set in flags.
[in]dst_lenLength of dst. Legal values are:
[in]src_panSource PAN ID in little-endian. May be 0 if IEEE802154_FCF_PAN_COMP is set in flags. Otherwise, it will be ignored, when IEEE802154_FCF_PAN_COMP is set.
[in]dst_panDestination PAN ID in little-endian.
[in]flagsFlags for the frame. These are interchangable with the first byte of the IEEE 802.15.4 FCF. This means that it encompasses the type values, IEEE802154_FCF_SECURITY_EN, IEEE802154_FCF_FRAME_PEND, and IEEE802154_FCF_ACK_REQ.
[in]seqSequence number for frame.

The version field in the FCF will be set implicitly to version 1.

Returns
Size of frame header on success.
0, on error (flags set to unexpected state).