Loading...
Searching...
No Matches
Generic network interface header

Detailed Description

Files

file  hdr.h
 Generic network interface header.
 

Data Structures

struct  gnrc_netif_hdr_t
 Generic network interface header. More...
 

Macros

#define GNRC_NETIF_HDR_L2ADDR_MAX_LEN   (8)
 Maximum length of the l2 addresses of the generic interface header in bytes.
 
#define GNRC_NETIF_HDR_L2ADDR_PRINT_LEN   (GNRC_NETIF_HDR_L2ADDR_MAX_LEN * 3)
 Maximum length of the string representatiom of l2 addresses of the generic interface header in bytes.
 
#define GNRC_NETIF_HDR_NO_RSSI   (INT16_MIN)
 Special value to indicate that no RSSI value is present.
 
#define GNRC_NETIF_HDR_NO_LQI   (0)
 Special value to indicate that no LQI value is present.
 

Functions

static void gnrc_netif_hdr_init (gnrc_netif_hdr_t *hdr, uint8_t src_l2addr_len, uint8_t dst_l2addr_len)
 Initialize the given generic network interface header.
 
static size_t gnrc_netif_hdr_sizeof (const gnrc_netif_hdr_t *hdr)
 Get the size of the given generic network interface header.
 
static uint8_t * gnrc_netif_hdr_get_src_addr (const gnrc_netif_hdr_t *hdr)
 Get the source address from the given header.
 
static void gnrc_netif_hdr_set_src_addr (gnrc_netif_hdr_t *hdr, const uint8_t *addr, uint8_t addr_len)
 Set the source address in the given header.
 
static uint8_t * gnrc_netif_hdr_get_dst_addr (const gnrc_netif_hdr_t *hdr)
 Get the destination address from the given header.
 
static void gnrc_netif_hdr_set_dst_addr (gnrc_netif_hdr_t *hdr, const uint8_t *addr, uint8_t addr_len)
 Set the destination address in the given header.
 
static void gnrc_netif_hdr_set_timestamp (gnrc_netif_hdr_t *hdr, uint64_t timestamp)
 Set the timestamp in the netif header.
 
static int gnrc_netif_hdr_get_timestamp (const gnrc_netif_hdr_t *hdr, uint64_t *dest)
 Get the timestamp of the frame in nanoseconds since epoch.
 
static int gnrc_netif_hdr_ipv6_iid_from_src (const gnrc_netif_t *netif, const gnrc_netif_hdr_t *hdr, eui64_t *iid)
 Converts the source address of a given Generic network interface header to an IPv6 IID.
 
static int gnrc_netif_hdr_ipv6_iid_from_dst (const gnrc_netif_t *netif, const gnrc_netif_hdr_t *hdr, eui64_t *iid)
 Converts the destination address of a given Generic network interface header to an IPv6 IID.
 
gnrc_pktsnip_tgnrc_netif_hdr_build (const uint8_t *src, uint8_t src_len, const uint8_t *dst, uint8_t dst_len)
 Builds a generic network interface header for sending and adds it to the packet buffer.
 
static gnrc_netif_tgnrc_netif_hdr_get_netif (const gnrc_netif_hdr_t *hdr)
 Convenience function to get the corresponding interface struct for a given interface header.
 
static void gnrc_netif_hdr_set_netif (gnrc_netif_hdr_t *hdr, const gnrc_netif_t *netif)
 Convenience function to set the interface of an interface header, given the network interface.
 
void gnrc_netif_hdr_print (gnrc_netif_hdr_t *hdr)
 Outputs a generic interface header to stdout.
 
uint8_t gnrc_netif_hdr_get_flag (gnrc_pktsnip_t *pkt)
 Fetch the netif header flags of a gnrc packet.
 
int gnrc_netif_hdr_get_dstaddr (gnrc_pktsnip_t *pkt, uint8_t **pointer_to_addr)
 Extract the destination address out of a gnrc packet.
 
int gnrc_netif_hdr_get_srcaddr (gnrc_pktsnip_t *pkt, uint8_t **pointer_to_addr)
 Extract the source address out of a gnrc packet.
 

Flags for the gnrc_netif_hdr_t

#define GNRC_NETIF_HDR_FLAGS_BROADCAST   (0x80)
 Send packet broadcast.
 
#define GNRC_NETIF_HDR_FLAGS_MULTICAST   (0x40)
 Send packet multicast.
 
#define GNRC_NETIF_HDR_FLAGS_MORE_DATA   (0x10)
 More data will follow.
 
#define GNRC_NETIF_HDR_FLAGS_TIMESTAMP   (0x08)
 Indicate presence of a valid timestamp.
 

Macro Definition Documentation

◆ GNRC_NETIF_HDR_FLAGS_BROADCAST

#define GNRC_NETIF_HDR_FLAGS_BROADCAST   (0x80)

Send packet broadcast.

Packets with this flag set must be send broadcast. gnrc_netif_hdr_t::dst_l2addr_len and any appended destination address must be ignored. If the link layer does not support broadcast the packet must be dropped silently.

Definition at line 76 of file hdr.h.

◆ GNRC_NETIF_HDR_FLAGS_MORE_DATA

#define GNRC_NETIF_HDR_FLAGS_MORE_DATA   (0x10)

More data will follow.

This flag signals that this packet is part of a burst of packets. The link layer implementation can choose to translate this flag into frame header bits to tell the remote node that more traffic will follow shortly. The most direct use case for this flag is to set it for fragmented packets in duty cycled networks to tell the remote node to keep its radio turned on after receiving the first fragment.

See also
The corresponding bit in the IEEE 802.15.4 frame control field, IEEE802154_FCF_FRAME_PEND

Definition at line 104 of file hdr.h.

◆ GNRC_NETIF_HDR_FLAGS_MULTICAST

#define GNRC_NETIF_HDR_FLAGS_MULTICAST   (0x40)

Send packet multicast.

Packets with this flag set must be send multicast. gnrc_netif_hdr_t::dst_l2addr_len and any appended destination address must be ignored. The context for the multicast address must be derived from the network layer destination address. If the link layer does not support multicast it should interpret this flag the same way it does GNRC_NETIF_HDR_FLAGS_BROADCAST.

Definition at line 89 of file hdr.h.

◆ GNRC_NETIF_HDR_FLAGS_TIMESTAMP

#define GNRC_NETIF_HDR_FLAGS_TIMESTAMP   (0x08)

Indicate presence of a valid timestamp.

If (and only if) module gnrc_netif_timestamp is used and the network device supplied the timestamp of reception of a frame, this timestamp is passed up the network stack through gnrc_netif_hdr_t::timestamp and this flag is set. This flag can be used to check for presence of a valid timestamp.

Definition at line 115 of file hdr.h.

◆ GNRC_NETIF_HDR_L2ADDR_MAX_LEN

#define GNRC_NETIF_HDR_L2ADDR_MAX_LEN   (8)

Maximum length of the l2 addresses of the generic interface header in bytes.

Definition at line 42 of file hdr.h.

◆ GNRC_NETIF_HDR_L2ADDR_PRINT_LEN

#define GNRC_NETIF_HDR_L2ADDR_PRINT_LEN   (GNRC_NETIF_HDR_L2ADDR_MAX_LEN * 3)

Maximum length of the string representatiom of l2 addresses of the generic interface header in bytes.

Definition at line 48 of file hdr.h.

◆ GNRC_NETIF_HDR_NO_LQI

#define GNRC_NETIF_HDR_NO_LQI   (0)

Special value to indicate that no LQI value is present.

See gnrc_netif_hdr_t::lqi

Definition at line 61 of file hdr.h.

◆ GNRC_NETIF_HDR_NO_RSSI

#define GNRC_NETIF_HDR_NO_RSSI   (INT16_MIN)

Special value to indicate that no RSSI value is present.

See gnrc_netif_hdr_t::rssi

Definition at line 55 of file hdr.h.

Function Documentation

◆ gnrc_netif_hdr_build()

gnrc_pktsnip_t * gnrc_netif_hdr_build ( const uint8_t *  src,
uint8_t  src_len,
const uint8_t *  dst,
uint8_t  dst_len 
)

Builds a generic network interface header for sending and adds it to the packet buffer.

Parameters
[in]srcSource address for the header. Can be NULL if not known or required.
[in]src_lenLength of src. Can be 0 if not known or required.
[in]dstDestination address for the header. Can be NULL if not known or required.
[in]dst_lenLength of dst. Can be 0 if not known or required.
Returns
The generic network layer header on success.
NULL on error.

◆ gnrc_netif_hdr_get_dst_addr()

static uint8_t * gnrc_netif_hdr_get_dst_addr ( const gnrc_netif_hdr_t hdr)
inlinestatic

Get the destination address from the given header.

Parameters
[in]hdrheader to read from
Returns
pointer to destination address on success
NULL on error

Definition at line 229 of file hdr.h.

◆ gnrc_netif_hdr_get_dstaddr()

int gnrc_netif_hdr_get_dstaddr ( gnrc_pktsnip_t pkt,
uint8_t **  pointer_to_addr 
)

Extract the destination address out of a gnrc packet.

Parameters
[in]pktgnrc packet from whom to extract
[out]pointer_to_addrpointer to address will be stored here
Returns
length of destination address
-ENOENT, if no netif header is presented in pkt or if no destination address field presented in netif header.

◆ gnrc_netif_hdr_get_flag()

uint8_t gnrc_netif_hdr_get_flag ( gnrc_pktsnip_t pkt)

Fetch the netif header flags of a gnrc packet.

Parameters
[in]pktgnrc packet from whom to fetch
Returns
netif header flags of pkt
0, if no header is present

◆ gnrc_netif_hdr_get_netif()

static gnrc_netif_t * gnrc_netif_hdr_get_netif ( const gnrc_netif_hdr_t hdr)
inlinestatic

Convenience function to get the corresponding interface struct for a given interface header.

Precondition
hdr != NULL
Parameters
[in]hdrHeader to read interface from.
Returns
The gnrc_netif_t representation of the interface on success
NULL, on error.

Definition at line 383 of file hdr.h.

◆ gnrc_netif_hdr_get_src_addr()

static uint8_t * gnrc_netif_hdr_get_src_addr ( const gnrc_netif_hdr_t hdr)
inlinestatic

Get the source address from the given header.

Parameters
[in]hdrheader to read from
Returns
pointer to source address on success
NULL on error

Definition at line 198 of file hdr.h.

◆ gnrc_netif_hdr_get_srcaddr()

int gnrc_netif_hdr_get_srcaddr ( gnrc_pktsnip_t pkt,
uint8_t **  pointer_to_addr 
)

Extract the source address out of a gnrc packet.

Parameters
[in]pktgnrc packet from whom to extract
[out]pointer_to_addrpointer to address will be stored here
Returns
length of source address
-ENOENT, if no netif header is presented in pkt or if no source address field presented in netif header.

◆ gnrc_netif_hdr_get_timestamp()

static int gnrc_netif_hdr_get_timestamp ( const gnrc_netif_hdr_t hdr,
uint64_t *  dest 
)
inlinestatic

Get the timestamp of the frame in nanoseconds since epoch.

Parameters
[in]hdrHeader to read the timestamp from
[out]destThe timestamp will be stored here
Return values
0The timestamp was stored in dest
-1No timestamp available, dest is unchanged

If the module gnrc_netif_timestamp is not used, this will always return 0

Definition at line 282 of file hdr.h.

◆ gnrc_netif_hdr_init()

static void gnrc_netif_hdr_init ( gnrc_netif_hdr_t hdr,
uint8_t  src_l2addr_len,
uint8_t  dst_l2addr_len 
)
inlinestatic

Initialize the given generic network interface header.

Parameters
[in]hdrheader to initialize
[in]src_l2addr_lenlink layer source address length
[in]dst_l2addr_lenlink layer destination address length

Definition at line 166 of file hdr.h.

◆ gnrc_netif_hdr_ipv6_iid_from_dst()

static int gnrc_netif_hdr_ipv6_iid_from_dst ( const gnrc_netif_t netif,
const gnrc_netif_hdr_t hdr,
eui64_t iid 
)
inlinestatic

Converts the destination address of a given Generic network interface header to an IPv6 IID.

Note
netif is intentionally required to be provided so that the caller needs to retrieve it from gnrc_netif_hdr_t::if_pid of hdr only once instead of this function retrieving it at every call.
Precondition
netif->pid == hdr->if_pid
Parameters
[in]netifA network interface. gnrc_netif_t::pid must be equal to gnrc_netif_hdr_t::if_pid of hdr.
[in]hdrHeader to convert destination address from.
[out]iidThe IID based on gnrc_netif_t::device_type.
Returns
same as gnrc_netif_ipv6_iid_from_addr().

Definition at line 341 of file hdr.h.

◆ gnrc_netif_hdr_ipv6_iid_from_src()

static int gnrc_netif_hdr_ipv6_iid_from_src ( const gnrc_netif_t netif,
const gnrc_netif_hdr_t hdr,
eui64_t iid 
)
inlinestatic

Converts the source address of a given Generic network interface header to an IPv6 IID.

Note
netif is intentionally required to be provided so that the caller needs to retrieve it from gnrc_netif_hdr_t::if_pid of hdr only once instead of this function retrieving it at every call.
Precondition
netif->pid == hdr->if_pid
Parameters
[in]netifA network interface. gnrc_netif_t::pid must be equal to gnrc_netif_hdr_t::if_pid of hdr.
[in]hdrHeader to convert source address from.
[out]iidThe IID based on gnrc_netif_t::device_type.
Returns
same as gnrc_netif_ipv6_iid_from_addr().

Definition at line 314 of file hdr.h.

◆ gnrc_netif_hdr_print()

void gnrc_netif_hdr_print ( gnrc_netif_hdr_t hdr)

Outputs a generic interface header to stdout.

Parameters
[in]hdrA generic interface header.

◆ gnrc_netif_hdr_set_dst_addr()

static void gnrc_netif_hdr_set_dst_addr ( gnrc_netif_hdr_t hdr,
const uint8_t *  addr,
uint8_t  addr_len 
)
inlinestatic

Set the destination address in the given header.

Parameters
[in]hdrheader to write to
[in]addrnew destination address
[in]addr_lenaddr length

Definition at line 241 of file hdr.h.

◆ gnrc_netif_hdr_set_netif()

static void gnrc_netif_hdr_set_netif ( gnrc_netif_hdr_t hdr,
const gnrc_netif_t netif 
)
inlinestatic

Convenience function to set the interface of an interface header, given the network interface.

Parameters
[out]hdrHeader to set the interface for.
[in]netifNetwork interface to set for hdr.

Definition at line 396 of file hdr.h.

◆ gnrc_netif_hdr_set_src_addr()

static void gnrc_netif_hdr_set_src_addr ( gnrc_netif_hdr_t hdr,
const uint8_t *  addr,
uint8_t  addr_len 
)
inlinestatic

Set the source address in the given header.

Parameters
[in]hdrheader to write to
[in]addrnew source address
[in]addr_lenaddr length

Definition at line 210 of file hdr.h.

◆ gnrc_netif_hdr_set_timestamp()

static void gnrc_netif_hdr_set_timestamp ( gnrc_netif_hdr_t hdr,
uint64_t  timestamp 
)
inlinestatic

Set the timestamp in the netif header.

Parameters
[out]hdrHeader to set the timestamp in
[in]timestampTimestamp to set (nanoseconds since epoch)

If the module gnrc_netif_timestamp is not used, a call to this function become a non-op (and will be fully optimized out by the compiler)

Definition at line 261 of file hdr.h.

◆ gnrc_netif_hdr_sizeof()

static size_t gnrc_netif_hdr_sizeof ( const gnrc_netif_hdr_t hdr)
inlinestatic

Get the size of the given generic network interface header.

Parameters
[in]hdrheader to get the size of
Returns
the size of the given header, including link layer addresses

Definition at line 185 of file hdr.h.