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 
83 typedef struct {
84  uint8_t src_l2addr_len;
85  uint8_t dst_l2addr_len;
87  uint8_t flags;
88  int16_t rssi;
89  uint8_t lqi;
91 
99 static inline void gnrc_netif_hdr_init(gnrc_netif_hdr_t *hdr, uint8_t src_l2addr_len,
100  uint8_t dst_l2addr_len)
101 {
102  hdr->src_l2addr_len = src_l2addr_len;
103  hdr->dst_l2addr_len = dst_l2addr_len;
104  hdr->if_pid = KERNEL_PID_UNDEF;
105  hdr->rssi = 0;
106  hdr->lqi = 0;
107  hdr->flags = 0;
108 }
109 
118 static inline size_t gnrc_netif_hdr_sizeof(gnrc_netif_hdr_t *hdr)
119 {
120  return sizeof(gnrc_netif_hdr_t) + hdr->src_l2addr_len + hdr->dst_l2addr_len;
121 }
122 
131 static inline uint8_t *gnrc_netif_hdr_get_src_addr(gnrc_netif_hdr_t *hdr)
132 {
133  return ((uint8_t *)(hdr + 1));
134 }
135 
143 static inline void gnrc_netif_hdr_set_src_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
144  uint8_t addr_len)
145 {
146  if (addr_len != hdr->src_l2addr_len) {
147  return;
148  }
149 
150  memcpy(((uint8_t *)(hdr + 1)), addr, addr_len);
151 }
152 
153 
162 static inline uint8_t *gnrc_netif_hdr_get_dst_addr(gnrc_netif_hdr_t *hdr)
163 {
164  return (((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len);
165 }
166 
174 static inline void gnrc_netif_hdr_set_dst_addr(gnrc_netif_hdr_t *hdr, uint8_t *addr,
175  uint8_t addr_len)
176 {
177  if (addr_len != hdr->dst_l2addr_len) {
178  return;
179  }
180 
181  memcpy(((uint8_t *)(hdr + 1)) + hdr->src_l2addr_len, addr, addr_len);
182 }
183 
198 gnrc_pktsnip_t *gnrc_netif_hdr_build(uint8_t *src, uint8_t src_len, uint8_t *dst, uint8_t dst_len);
199 
206 
216 
227 int gnrc_netif_hdr_get_dstaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
228 
239 int gnrc_netif_hdr_get_srcaddr(gnrc_pktsnip_t* pkt, uint8_t** pointer_to_addr);
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif /* NET_GNRC_NETIF_HDR_H */
246 
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)