2015-02-12 19:31:38 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-08-17 15:41:29 +02:00
|
|
|
* @defgroup net_gnrc_netif_hdr Generic network interface header
|
|
|
|
* @ingroup net_gnrc_netif
|
2015-02-12 19:31:38 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Generic network interface header
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2015-03-07 16:53:52 +01:00
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
2015-02-12 19:31:38 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#ifndef NET_GNRC_NETIF_HDR_H
|
|
|
|
#define NET_GNRC_NETIF_HDR_H
|
2015-02-12 19:31:38 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-08-17 15:41:29 +02:00
|
|
|
#include "net/gnrc/pkt.h"
|
|
|
|
#include "net/gnrc/pktbuf.h"
|
2015-02-12 19:31:38 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-04-20 10:54:03 +02:00
|
|
|
/**
|
|
|
|
* @brief Maximum length of the l2 addresses of the generic interface header
|
|
|
|
* in bytes.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
#define GNRC_NETIF_HDR_L2ADDR_MAX_LEN (8)
|
2017-03-02 18:15:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum length of the string representatiom of l2 addresses of the
|
|
|
|
* generic interface header in bytes.
|
|
|
|
*/
|
2016-04-10 13:21:14 +02:00
|
|
|
#define GNRC_NETIF_HDR_L2ADDR_PRINT_LEN (GNRC_NETIF_HDR_L2ADDR_MAX_LEN * 3)
|
2015-04-20 10:54:03 +02:00
|
|
|
|
2015-03-27 22:14:32 +01:00
|
|
|
/**
|
|
|
|
* @{
|
2015-08-17 15:41:29 +02:00
|
|
|
* @name Flags for the gnrc_netif_hdr_t
|
2015-03-27 22:14:32 +01:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Send packet broadcast.
|
|
|
|
*
|
|
|
|
* @details Packets with this flag set must be send broadcast.
|
2015-08-17 15:41:29 +02:00
|
|
|
* gnrc_netif_hdr_t::dst_l2addr_len and any appended destination
|
2015-03-27 22:14:32 +01:00
|
|
|
* address must be ignored.
|
|
|
|
* If the link layer does not support broadcast the packet must be
|
|
|
|
* dropped silently.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
#define GNRC_NETIF_HDR_FLAGS_BROADCAST (0x80)
|
2015-03-27 22:14:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send packet multicast.
|
|
|
|
*
|
|
|
|
* @details Packets with this flag set must be send multicast.
|
2015-08-17 15:41:29 +02:00
|
|
|
* gnrc_netif_hdr_t::dst_l2addr_len and any appended destination
|
2015-03-27 22:14:32 +01:00
|
|
|
* 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
|
2015-08-17 15:41:29 +02:00
|
|
|
* this flag the same way it does @ref GNRC_NETIF_HDR_FLAGS_BROADCAST.
|
2015-03-27 22:14:32 +01:00
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
#define GNRC_NETIF_HDR_FLAGS_MULTICAST (0x40)
|
2018-06-30 15:30:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief More data will follow
|
|
|
|
*
|
|
|
|
* @details 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 The corresponding bit in the IEEE 802.15.4 frame control field,
|
|
|
|
* @ref IEEE802154_FCF_FRAME_PEND
|
|
|
|
*/
|
|
|
|
#define GNRC_NETIF_HDR_FLAGS_MORE_DATA (0x10)
|
2015-03-27 22:14:32 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2015-02-12 19:31:38 +01:00
|
|
|
/**
|
|
|
|
* @brief Generic network interface header
|
|
|
|
*
|
|
|
|
* The link layer addresses included in this header are put in memory directly
|
|
|
|
* following this struct.
|
|
|
|
*/
|
2015-07-13 14:24:01 +02:00
|
|
|
typedef struct {
|
2015-02-12 19:31:38 +01:00
|
|
|
uint8_t src_l2addr_len; /**< length of l2 source address in byte */
|
|
|
|
uint8_t dst_l2addr_len; /**< length of l2 destination address in byte */
|
|
|
|
kernel_pid_t if_pid; /**< PID of network interface */
|
2015-03-27 22:14:32 +01:00
|
|
|
uint8_t flags; /**< flags as defined above */
|
2015-02-12 19:31:38 +01:00
|
|
|
uint8_t lqi; /**< lqi of received packet (optional) */
|
2018-05-14 14:01:29 +02:00
|
|
|
int16_t rssi; /**< rssi of received packet in dBm (optional) */
|
2015-08-17 15:41:29 +02:00
|
|
|
} gnrc_netif_hdr_t;
|
2015-02-12 19:31:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the given generic network interface header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to initialize
|
|
|
|
* @param[in] src_l2addr_len link layer source address length
|
|
|
|
* @param[in] dst_l2addr_len link layer destination address length
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline void gnrc_netif_hdr_init(gnrc_netif_hdr_t *hdr, uint8_t src_l2addr_len,
|
|
|
|
uint8_t dst_l2addr_len)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
|
|
|
hdr->src_l2addr_len = src_l2addr_len;
|
|
|
|
hdr->dst_l2addr_len = dst_l2addr_len;
|
|
|
|
hdr->if_pid = KERNEL_PID_UNDEF;
|
|
|
|
hdr->rssi = 0;
|
|
|
|
hdr->lqi = 0;
|
2015-03-27 22:14:32 +01:00
|
|
|
hdr->flags = 0;
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the size of the given generic network interface header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to get the size of
|
|
|
|
*
|
|
|
|
* @return the size of the given header, including link layer
|
|
|
|
* addresses
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline size_t gnrc_netif_hdr_sizeof(gnrc_netif_hdr_t *hdr)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
2015-08-17 15:41:29 +02:00
|
|
|
return sizeof(gnrc_netif_hdr_t) + hdr->src_l2addr_len + hdr->dst_l2addr_len;
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the source address from the given header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to read from
|
|
|
|
*
|
|
|
|
* @return pointer to source address on success
|
|
|
|
* @return NULL on error
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline uint8_t *gnrc_netif_hdr_get_src_addr(gnrc_netif_hdr_t *hdr)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
2015-03-09 17:36:33 +01:00
|
|
|
return ((uint8_t *)(hdr + 1));
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the source address in the given header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to write to
|
|
|
|
* @param[in] addr new source address
|
|
|
|
* @param[in] addr_len *addr* length
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline void gnrc_netif_hdr_set_src_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
|
2015-03-08 22:53:56 +01:00
|
|
|
uint8_t addr_len)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
|
|
|
if (addr_len != hdr->src_l2addr_len) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-08 22:53:56 +01:00
|
|
|
|
2015-03-09 17:36:33 +01:00
|
|
|
memcpy(((uint8_t *)(hdr + 1)), addr, addr_len);
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the destination address from the given header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to read from
|
|
|
|
*
|
|
|
|
* @return pointer to destination address on success
|
|
|
|
* @return NULL on error
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline uint8_t *gnrc_netif_hdr_get_dst_addr(gnrc_netif_hdr_t *hdr)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
2015-03-09 17:36:33 +01:00
|
|
|
return (((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len);
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the destination address in the given header
|
|
|
|
*
|
|
|
|
* @param[in] hdr header to write to
|
|
|
|
* @param[in] addr new destination address
|
|
|
|
* @param[in] addr_len *addr* length
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
static inline void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
|
2015-03-08 22:53:56 +01:00
|
|
|
uint8_t addr_len)
|
2015-02-12 19:31:38 +01:00
|
|
|
{
|
|
|
|
if (addr_len != hdr->dst_l2addr_len) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-08 22:53:56 +01:00
|
|
|
|
2015-03-09 17:36:33 +01:00
|
|
|
memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len);
|
2015-02-12 19:31:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-07 16:53:52 +01:00
|
|
|
/**
|
|
|
|
* @brief Builds a generic network interface header for sending and
|
|
|
|
* adds it to the packet buffer.
|
|
|
|
*
|
|
|
|
* @param[in] src Source address for the header. Can be NULL if not
|
|
|
|
* known or required.
|
|
|
|
* @param[in] src_len Length of @p src. Can be 0 if not known or required.
|
|
|
|
* @param[in] dst Destination address for the header. Can be NULL if not
|
|
|
|
* known or required.
|
|
|
|
* @param[in] dst_len Length of @p dst. Can be 0 if not known or required.
|
|
|
|
*
|
|
|
|
* @return The generic network layer header on success.
|
|
|
|
* @return NULL on error.
|
|
|
|
*/
|
2015-11-18 07:26:44 +01:00
|
|
|
gnrc_pktsnip_t *gnrc_netif_hdr_build(uint8_t *src, uint8_t src_len, uint8_t *dst, uint8_t dst_len);
|
2015-03-07 16:53:52 +01:00
|
|
|
|
2015-04-20 10:54:03 +02:00
|
|
|
/**
|
|
|
|
* @brief Outputs a generic interface header to stdout.
|
|
|
|
*
|
|
|
|
* @param[in] hdr A generic interface header.
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
void gnrc_netif_hdr_print(gnrc_netif_hdr_t *hdr);
|
2015-04-20 10:54:03 +02:00
|
|
|
|
2017-03-02 18:15:46 +01:00
|
|
|
/**
|
|
|
|
* @brief Fetch the netif header flags of a gnrc packet
|
2016-11-07 18:18:19 +01:00
|
|
|
*
|
|
|
|
* @param[in] pkt gnrc packet from whom to fetch
|
|
|
|
*
|
|
|
|
* @return netif header flags of @p pkt
|
|
|
|
* @return 0, if no header is present
|
|
|
|
*/
|
|
|
|
uint8_t gnrc_netif_hdr_get_flag(gnrc_pktsnip_t* pkt);
|
|
|
|
|
2017-03-02 18:15:46 +01:00
|
|
|
/**
|
|
|
|
* @brief Extract the destination address out of a gnrc packet
|
2016-11-07 18:18:19 +01:00
|
|
|
*
|
|
|
|
* @param[in] pkt gnrc packet from whom to extract
|
|
|
|
* @param[out] pointer_to_addr pointer to address will be stored here
|
|
|
|
*
|
|
|
|
* @return length of destination address
|
|
|
|
* @return -ENOENT, if no netif header is presented in @p pkt or if no
|
|
|
|
* destination address field presented in netif header.
|
|
|
|
*/
|
|
|
|
int gnrc_netif_hdr_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
|
|
|
|
|
2017-03-02 18:15:46 +01:00
|
|
|
/**
|
|
|
|
* @brief Extract the source address out of a gnrc packet
|
2016-11-07 18:18:19 +01:00
|
|
|
*
|
|
|
|
* @param[in] pkt gnrc packet from whom to extract
|
|
|
|
* @param[out] pointer_to_addr pointer to address will be stored here
|
|
|
|
*
|
|
|
|
* @return length of source address
|
|
|
|
* @return -ENOENT, if no netif header is presented in @p pkt or if no
|
|
|
|
* source address field presented in netif header.
|
|
|
|
*/
|
|
|
|
int gnrc_netif_hdr_get_srcaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
|
|
|
|
|
2015-02-12 19:31:38 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* NET_GNRC_NETIF_HDR_H */
|
2015-02-12 19:31:38 +01:00
|
|
|
/** @} */
|