diff --git a/sys/include/net/ng_ifhdr.h b/sys/include/net/ng_ifhdr.h new file mode 100644 index 000000000000..5f8e7da04383 --- /dev/null +++ b/sys/include/net/ng_ifhdr.h @@ -0,0 +1,138 @@ +/* + * 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. + */ + +/** + * @ingroup net + * @{ + * + * @file + * @brief Generic network interface header + * + * @author Hauke Petersen + */ + +#ifndef IFHDR_H_ +#define IFHDR_H_ + +#include +#include + +#include "kernel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Generic network interface header + * + * The link layer addresses included in this header are put in memory directly + * following this struct. + */ +typedef struct __attribute__((packed)) { + 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 */ + uint8_t rssi; /**< rssi of received packet (optional) */ + uint8_t lqi; /**< lqi of received packet (optional) */ +} ng_ifhdr_t; + +/** + * @brief Initialize the given generic link layer header + * + * @param[in] hdr header to initialize + * @param[in] src_addr_len link layer source address length + * @param[in] dst_addr_len link layer destination address length + */ +inline void ng_ifhdr_init(ng_ifhdr_t *hdr, uint8_t src_addr_len, + uint8_t dst_addr_len) +{ + hdr->src_addr_len = src_addr_len; + hdr->dst_addr_len = dst_addr_len; + hdr->if_pid = KERNEL_PID_UNDEF; + hdr->rssi = 0; + hdr->lqi = 0; +} + +/** + * @brief Get the size of the given generic link layer header + * + * @param[in] hdr header to get the size of + * + * @return the size of the given header + */ +inline size_t ng_ifhdr_sizeof(ng_ifhdr_t *hdr) +{ + return sizeof(ng_ifhdr_t) + hdr->src_addr_len + hdr->dst_addr_len; +} + +/** + * @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 + */ +inline uint8_t *ng_ifhdr_get_src_addr(ng_ifhdr_t *hdr) +{ + return ((uint8_t *)hdr) + sizeof(ng_ifhdr_t); +} + +/** + * @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 + */ +inline void ng_ifhdr_set_src_addr(ng_ifhdr_t *hdr, uint8_t *addr, + uint8_t addr_len) +{ + if (addr_len != hdr->src_addr_len) { + return; + } + memcpy(((uint8_t *)hdr) + sizeof(ng_ifhdr_t), addr, addr_len); +} + + +/** + * @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 + */ +inline uint8_t *ng_ifhdr_get_dst_addr(ng_ifhdr_t *hdr) +{ + return ((uint8_t *)hdr) + sizeof(ng_ifhdr_t) + hdr->src_addr_len; +} + +/** + * @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 + */ +inline void ng_ifhdr_set_dst_addr(ng_ifhdr_t *hdr, uint8_t *addr, + uint8_t addr_len) +{ + if (addr_len != hdr->dst_addr_len) { + return; + } + memcpy(((uint8_t *)hdr) + sizeof(ng_ifhdr_t) + hdr->addr_len, addr, addr_len); +} + +#ifdef __cplusplus +} +#endif + +#endif /* IFHDR_H_ */ +/** @} */ diff --git a/sys/include/net/ng_llhdr.h b/sys/include/net/ng_llhdr.h deleted file mode 100644 index 068dd4c7f406..000000000000 --- a/sys/include/net/ng_llhdr.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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. - */ - -/** - * @ingroup net - * @{ - * - * @file - * @brief Generic link layer header - * - * @author Hauke Petersen - */ - -#ifndef LLHDR_H_ -#define LLHDR_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Generic link layer header - * - * The actual addresses are put into the memory following this datastructure. - */ -typedef struct __attribute__((packed)) { - uint8_t addr_len; /**< link layer address length in byte */ - uint8_t rssi; /**< rssi of received packet (optional) */ - uint8_t lqi; /**< lqi of received packet (optional) */ - uint8_t options; /**< any optional options */ -} llhdr_t; - -/** - * @brief Initialize the given generic link layer header - * - * @param[in] hdr header to initialize - * @param[in] addr_len link layer address length - */ -inline void llhdr_init(llhdr_t *hdr, uint8_t addr_len) -{ - hdr->addr_len = addr_len; - hdr->rssi = 0; - hdr->lqi = 0; -} - -/** - * @brief Get the size of the given generic link layer header - * - * @param[in] hdr header to get the size of - * - * @return the size of the given header - */ -inline size_t llhdr_sizeof(llhdr_t *hdr) -{ - return sizeof(llhdr_t) + hdr->addr_len + hdr->addr_len; -} - -/** - * @brief Get the source address from the given header - * - * @param[in] hdr header to read from - * @param[in] addr buffer to write to - * @param[in] addr_len maximum number of bytes to read - */ -inline void llhdr_get_src_addr(llhdr_t *hdr, uint8_t *addr, uint8_t addr_len) -{ - memcpy(addr, (hdr + sizeof(llhdr_t)), hdr->addr_len); -} - -/** - * @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 - */ -inline void llhdr_set_src_addr(llhdr_t *hdr, uint8_t *addr, uint8_t addr_len) -{ - memcpy((hdr + sizeof(llhdr_t)), addr, addr_len); -} - - -/** - * @brief Get the destination address from the given header - * - * @param[in] hdr header to read from - * @param[in] addr buffer to write to - * @param[in] addr_len maximum number of bytes to read - */ -inline void llhdr_get_dst_addr(llhdr_t *hdr, uint8_t *addr, uint8_t addr_len) -{ - memcpy(addr, (hdr + sizeof(llhdr_t) + hdr->addr_len), hdr->addr_len); -} - -/** - * @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 - */ -inline void llhdr_set_dst_addr(llhdr_t *hdr, uint8_t *addr, uint8_t addr_len) -{ - memcpy((hdr + sizeof(llhdr_t) + hdr->addr_len), addr, addr_len); -} - -#ifdef __cplusplus -} -#endif - -#endif /* LL_GEN_FRAME_H_ */ -/** @} */