nettype.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
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 
32 #ifndef NET_GNRC_NETTYPE_H
33 #define NET_GNRC_NETTYPE_H
34 
35 #include <inttypes.h>
36 
37 #include "kernel_defines.h"
38 #include "net/ethertype.h"
39 #include "net/protnum.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
50 typedef enum {
58 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
60 #endif
61 
66 #if IS_USED(MODULE_GNRC_NETTYPE_GOMACH) || defined(DOXYGEN)
68 #endif
69 
77 #if IS_USED(MODULE_GNRC_NETTYPE_LWMAC) || defined(DOXYGEN)
79 #endif
80 
88 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
90 #endif
91 
99 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
101 #endif
102 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
104 #endif
105 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
107 #endif
108 
116 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
118 #endif
119 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
121 #endif
122 
126 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
130 #endif
131 
132 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
134 #endif
135 
136 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
138 #endif
139 
144 #ifdef TEST_SUITES
145  GNRC_NETTYPE_TEST,
146 #endif
147 
153 
164 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
165 {
166  switch (type) {
167 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
168  case ETHERTYPE_IPV6:
169  return GNRC_NETTYPE_IPV6;
170 #endif
171 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
172  case ETHERTYPE_NDN:
173 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
174  return GNRC_NETTYPE_CCN;
175 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
176  return GNRC_NETTYPE_NDN;
177 #endif
178 #endif
179 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
180  case ETHERTYPE_6LOENC:
181  return GNRC_NETTYPE_SIXLOWPAN;
182 #endif
183 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
184  case ETHERTYPE_CUSTOM:
185  return GNRC_NETTYPE_CUSTOM;
186 #endif
187  default:
188  return GNRC_NETTYPE_UNDEF;
189  }
190 }
191 
202 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
203 {
204  switch (type) {
205 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
207  return ETHERTYPE_6LOENC;
208 #endif
209 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
210  case GNRC_NETTYPE_IPV6:
211  return ETHERTYPE_IPV6;
212 #endif
213 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
214  case GNRC_NETTYPE_CCN:
215  return ETHERTYPE_NDN;
216 #endif
217 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
218  case GNRC_NETTYPE_NDN:
219  return ETHERTYPE_NDN;
220 #endif
221 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
222  case GNRC_NETTYPE_CUSTOM:
223  return ETHERTYPE_CUSTOM;
224 #endif
225  default:
226  return ETHERTYPE_UNKNOWN;
227  }
228 }
229 
241 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
242 {
243  switch (num) {
244 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
245  case PROTNUM_ICMPV6:
246  return GNRC_NETTYPE_ICMPV6;
247 #endif
248 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
249  case PROTNUM_IPV6:
250  return GNRC_NETTYPE_IPV6;
251 #endif
252 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
253  case PROTNUM_TCP:
254  return GNRC_NETTYPE_TCP;
255 #endif
256 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
257  case PROTNUM_UDP:
258  return GNRC_NETTYPE_UDP;
259 #endif
260 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
263  case PROTNUM_IPV6_EXT_RH:
265  case PROTNUM_IPV6_EXT_AH:
268  return GNRC_NETTYPE_IPV6_EXT;
269 #endif
270  default:
271  return GNRC_NETTYPE_UNDEF;
272  }
273 }
274 
286 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
287 {
288  switch (type) {
289 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
290  case GNRC_NETTYPE_ICMPV6:
291  return PROTNUM_ICMPV6;
292 #endif
293 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
294  case GNRC_NETTYPE_IPV6:
295  return PROTNUM_IPV6;
296 #endif
297 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
298  case GNRC_NETTYPE_TCP:
299  return PROTNUM_TCP;
300 #endif
301 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
302  case GNRC_NETTYPE_UDP:
303  return PROTNUM_UDP;
304 #endif
305  default:
306  return PROTNUM_RESERVED;
307  }
308 }
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 #endif /* NET_GNRC_NETTYPE_H */
315 
ETHERTYPE_IPV6
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:39
GNRC_NETTYPE_CCN_CHUNK
@ GNRC_NETTYPE_CCN_CHUNK
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:128
protnum.h
Protocol number definitions.
PROTNUM_UDP
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:52
GNRC_NETTYPE_UDP
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition: nettype.h:120
ETHERTYPE_UNKNOWN
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:58
PROTNUM_IPV6_EXT_FRAG
#define PROTNUM_IPV6_EXT_FRAG
Fragment Header for IPv6.
Definition: protnum.h:79
PROTNUM_IPV6_EXT_AH
#define PROTNUM_IPV6_EXT_AH
IPv6 Authentication Extension Header.
Definition: protnum.h:87
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
PROTNUM_RESERVED
#define PROTNUM_RESERVED
Reserved.
Definition: protnum.h:179
GNRC_NETTYPE_ICMPV6
@ GNRC_NETTYPE_ICMPV6
Protocol is ICMPv6.
Definition: nettype.h:106
GNRC_NETTYPE_IPV6_EXT
@ GNRC_NETTYPE_IPV6_EXT
Protocol is IPv6 extension header.
Definition: nettype.h:103
GNRC_NETTYPE_NUMOF
@ GNRC_NETTYPE_NUMOF
maximum number of available protocols
Definition: nettype.h:151
GNRC_NETTYPE_NDN
@ GNRC_NETTYPE_NDN
Protocol is NDN.
Definition: nettype.h:133
gnrc_nettype_from_ethertype
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to Protocol type.
Definition: nettype.h:164
gnrc_nettype_from_protnum
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to Protocol type.
Definition: nettype.h:241
PROTNUM_TCP
#define PROTNUM_TCP
Transmission Control.
Definition: protnum.h:40
PROTNUM_IPV6_EXT_HOPOPT
#define PROTNUM_IPV6_EXT_HOPOPT
IPv6 Hop-by-Hop Option.
Definition: protnum.h:34
ETHERTYPE_6LOENC
#define ETHERTYPE_6LOENC
6LoWPAN encapsulation
Definition: ethertype.h:40
ETHERTYPE_CUSTOM
#define ETHERTYPE_CUSTOM
Custom ethertype.
Definition: ethertype.h:52
GNRC_NETTYPE_IPV6
@ GNRC_NETTYPE_IPV6
Protocol is IPv6.
Definition: nettype.h:100
GNRC_NETTYPE_CCN
@ GNRC_NETTYPE_CCN
Protocol is CCN.
Definition: nettype.h:127
PROTNUM_IPV6_EXT_DST
#define PROTNUM_IPV6_EXT_DST
IPv6 Extension Header: Destination Options.
Definition: protnum.h:98
GNRC_NETTYPE_CUSTOM
@ GNRC_NETTYPE_CUSTOM
Custom ethertype.
Definition: nettype.h:89
PROTNUM_IPV6_EXT_MOB
#define PROTNUM_IPV6_EXT_MOB
IPv6 Mobility Extension Header.
Definition: protnum.h:171
GNRC_NETTYPE_LORAWAN
@ GNRC_NETTYPE_LORAWAN
Protocol is LoRaWAN.
Definition: nettype.h:137
gnrc_nettype_t
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
gnrc_nettype_to_ethertype
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates Protocol type to an Ether Type number.
Definition: nettype.h:202
GNRC_NETTYPE_UNDEF
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition: nettype.h:56
GNRC_NETTYPE_TCP
@ GNRC_NETTYPE_TCP
Protocol is TCP.
Definition: nettype.h:117
GNRC_NETTYPE_LWMAC
@ GNRC_NETTYPE_LWMAC
Protocol is lwMAC.
Definition: nettype.h:78
gnrc_nettype_to_protnum
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:286
PROTNUM_IPV6_EXT_RH
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:78
PROTNUM_ICMPV6
#define PROTNUM_ICMPV6
ICMP for IPv6.
Definition: protnum.h:96
PROTNUM_IPV6_EXT_ESP
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:85
ETHERTYPE_NDN
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:38
GNRC_NETTYPE_SIXLOWPAN
@ GNRC_NETTYPE_SIXLOWPAN
Protocol is 6LoWPAN.
Definition: nettype.h:59
PROTNUM_IPV6
#define PROTNUM_IPV6
IPv6 encapsulation.
Definition: protnum.h:76
GNRC_NETTYPE_NETIF
@ GNRC_NETTYPE_NETIF
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:55
inttypes.h
Adds include for missing inttype definitions.
ethertype.h
Ether type definitions.
GNRC_NETTYPE_GOMACH
@ GNRC_NETTYPE_GOMACH
Protocol is GoMacH.
Definition: nettype.h:67