gnrc/netif/hdr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef NET_GNRC_NETIF_HDR_H
22 #define NET_GNRC_NETIF_HDR_H
23 
24 #include <string.h>
25 #include <stdint.h>
26 
27 #include "net/gnrc/pkt.h"
28 #include "net/gnrc/pktbuf.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
38 #define GNRC_NETIF_HDR_L2ADDR_MAX_LEN (8)
39 
44 #define GNRC_NETIF_HDR_L2ADDR_PRINT_LEN (GNRC_NETIF_HDR_L2ADDR_MAX_LEN * 3)
45 
59 #define GNRC_NETIF_HDR_FLAGS_BROADCAST (0x80)
60 
72 #define GNRC_NETIF_HDR_FLAGS_MULTICAST (0x40)
73 
87 #define GNRC_NETIF_HDR_FLAGS_MORE_DATA (0x10)
88 
98 typedef struct {
99  uint8_t src_l2addr_len;
100  uint8_t dst_l2addr_len;
102  uint8_t flags;
103  uint8_t lqi;
104  int16_t rssi;
106 
114 static inline void gnrc_netif_hdr_init(gnrc_netif_hdr_t *hdr, uint8_t src_l2addr_len,
115  uint8_t dst_l2addr_len)
116 {
117  hdr->src_l2addr_len = src_l2addr_len;
118  hdr->dst_l2addr_len = dst_l2addr_len;
119  hdr->if_pid = KERNEL_PID_UNDEF;
120  hdr->rssi = 0;
121  hdr->lqi = 0;
122  hdr->flags = 0;
123 }
124 
133 static inline size_t gnrc_netif_hdr_sizeof(gnrc_netif_hdr_t *hdr)
134 {
135  return sizeof(gnrc_netif_hdr_t) + hdr->src_l2addr_len + hdr->dst_l2addr_len;
136 }
137 
146 static inline uint8_t *gnrc_netif_hdr_get_src_addr(gnrc_netif_hdr_t *hdr)
147 {
148  return ((uint8_t *)(hdr + 1));
149 }
150 
158 static inline void gnrc_netif_hdr_set_src_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
159  uint8_t addr_len)
160 {
161  if (addr_len != hdr->src_l2addr_len) {
162  return;
163  }
164 
165  memcpy(((uint8_t *)(hdr + 1)), addr, addr_len);
166 }
167 
168 
177 static inline uint8_t *gnrc_netif_hdr_get_dst_addr(gnrc_netif_hdr_t *hdr)
178 {
179  return (((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len);
180 }
181 
189 static inline void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
190  uint8_t addr_len)
191 {
192  if (addr_len != hdr->dst_l2addr_len) {
193  return;
194  }
195 
196  memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len);
197 }
198 
213 gnrc_pktsnip_t *gnrc_netif_hdr_build(uint8_t *src, uint8_t src_len, uint8_t *dst, uint8_t dst_len);
214 
221 
231 
242 int gnrc_netif_hdr_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
243 
254 int gnrc_netif_hdr_get_srcaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* NET_GNRC_NETIF_HDR_H */
261 
static void gnrc_netif_hdr_set_src_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr, uint8_t addr_len)
Set the source address in the given header.
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.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
General definitions for network packets and their helper functions.
static uint8_t * gnrc_netif_hdr_get_src_addr(gnrc_netif_hdr_t *hdr)
Get the source address from the given header.
Interface definition for the global network buffer.
uint8_t lqi
lqi of received packet (optional)
static void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr, uint8_t addr_len)
Set the destination address in the given header.
uint8_t dst_l2addr_len
length of l2 destination address in byte
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.
#define KERNEL_PID_UNDEF
Canonical identifier for an invalid PID.
Definition: kernel_types.h:63
Generic network interface header.
gnrc_pktsnip_t * gnrc_netif_hdr_build(uint8_t *src, uint8_t src_len, uint8_t *dst, uint8_t dst_len)
Builds a generic network interface header for sending and adds it to the packet buffer.
uint8_t flags
flags as defined above
static size_t gnrc_netif_hdr_sizeof(gnrc_netif_hdr_t *hdr)
Get the size of the given generic network interface header.
uint8_t src_l2addr_len
length of l2 source address in byte
void gnrc_netif_hdr_print(gnrc_netif_hdr_t *hdr)
Outputs a generic interface header to stdout.
Type to represent parts (either headers or payload) of a packet, called snips.
kernel_pid_t if_pid
PID of network interface.
int gnrc_netif_hdr_get_srcaddr(gnrc_pktsnip_t *pkt, uint8_t **pointer_to_addr)
Extract the source address out of a gnrc packet.
static uint8_t * gnrc_netif_hdr_get_dst_addr(gnrc_netif_hdr_t *hdr)
Get the destination address from the given header.
int16_t rssi
rssi of received packet in dBm (optional)