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 {
67 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
69 #endif
70 
75 #if IS_USED(MODULE_GNRC_NETTYPE_GOMACH) || defined(DOXYGEN)
77 #endif
78 
86 #if IS_USED(MODULE_GNRC_NETTYPE_LWMAC) || defined(DOXYGEN)
88 #endif
89 
97 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
99 #endif
100 
108 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
110 #endif
111 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
113 #endif
114 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
116 #endif
117 
125 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
127 #endif
128 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
130 #endif
131 
135 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
139 #endif
140 
141 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
143 #endif
144 
145 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
147 #endif
148 
153 #ifdef TEST_SUITES
154  GNRC_NETTYPE_TEST,
155 #endif
156 
162 
173 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
174 {
175  switch (type) {
176 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
177  case ETHERTYPE_IPV6:
178  return GNRC_NETTYPE_IPV6;
179 #endif
180 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
181  case ETHERTYPE_NDN:
182 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
183  return GNRC_NETTYPE_CCN;
184 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
185  return GNRC_NETTYPE_NDN;
186 #endif
187 #endif
188 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
189  case ETHERTYPE_6LOENC:
190  return GNRC_NETTYPE_SIXLOWPAN;
191 #endif
192 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
193  case ETHERTYPE_CUSTOM:
194  return GNRC_NETTYPE_CUSTOM;
195 #endif
196  default:
197  return GNRC_NETTYPE_UNDEF;
198  }
199 }
200 
211 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
212 {
213  switch (type) {
214 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
216  return ETHERTYPE_6LOENC;
217 #endif
218 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
219  case GNRC_NETTYPE_IPV6:
220  return ETHERTYPE_IPV6;
221 #endif
222 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
223  case GNRC_NETTYPE_CCN:
224  return ETHERTYPE_NDN;
225 #endif
226 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
227  case GNRC_NETTYPE_NDN:
228  return ETHERTYPE_NDN;
229 #endif
230 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
231  case GNRC_NETTYPE_CUSTOM:
232  return ETHERTYPE_CUSTOM;
233 #endif
234  default:
235  return ETHERTYPE_UNKNOWN;
236  }
237 }
238 
250 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
251 {
252  switch (num) {
253 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
254  case PROTNUM_ICMPV6:
255  return GNRC_NETTYPE_ICMPV6;
256 #endif
257 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
258  case PROTNUM_IPV6:
259  return GNRC_NETTYPE_IPV6;
260 #endif
261 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
262  case PROTNUM_TCP:
263  return GNRC_NETTYPE_TCP;
264 #endif
265 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
266  case PROTNUM_UDP:
267  return GNRC_NETTYPE_UDP;
268 #endif
269 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
272  case PROTNUM_IPV6_EXT_RH:
274  case PROTNUM_IPV6_EXT_AH:
277  return GNRC_NETTYPE_IPV6_EXT;
278 #endif
279  default:
280  return GNRC_NETTYPE_UNDEF;
281  }
282 }
283 
295 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
296 {
297  switch (type) {
298 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
299  case GNRC_NETTYPE_ICMPV6:
300  return PROTNUM_ICMPV6;
301 #endif
302 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
303  case GNRC_NETTYPE_IPV6:
304  return PROTNUM_IPV6;
305 #endif
306 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
307  case GNRC_NETTYPE_TCP:
308  return PROTNUM_TCP;
309 #endif
310 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
311  case GNRC_NETTYPE_UDP:
312  return PROTNUM_UDP;
313 #endif
314  default:
315  return PROTNUM_RESERVED;
316  }
317 }
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 
323 #endif /* NET_GNRC_NETTYPE_H */
324 
Protocol number definitions.
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:39
Protocol is LoRaWAN.
Definition: nettype.h:146
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:58
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:295
#define PROTNUM_IPV6_EXT_HOPOPT
IPv6 Hop-by-Hop Option.
Definition: protnum.h:34
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates Protocol type to an Ether Type number.
Definition: nettype.h:211
#define PROTNUM_IPV6_EXT_AH
IPv6 Authentication Extension Header.
Definition: protnum.h:89
#define PROTNUM_TCP
Transmission Control.
Definition: protnum.h:40
#define PROTNUM_IPV6_EXT_MOB
IPv6 Mobility Extension Header.
Definition: protnum.h:177
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:137
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to Protocol type.
Definition: nettype.h:173
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:86
#define ETHERTYPE_6LOENC
6LoWPAN encapsulation
Definition: ethertype.h:40
Protocol is lwMAC.
Definition: nettype.h:87
Protocol is NDN.
Definition: nettype.h:142
Protocol is UDP.
Definition: nettype.h:129
Protocol is IPv6 extension header.
Definition: nettype.h:112
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:79
Protocol is undefined.
Definition: nettype.h:65
Protocol is GoMacH.
Definition: nettype.h:76
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:64
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:53
maximum number of available protocols
Definition: nettype.h:160
Ether type definitions.
#define PROTNUM_ICMPV6
ICMP for IPv6.
Definition: protnum.h:100
Adds include for missing inttype definitions.
#define PROTNUM_RESERVED
Reserved.
Definition: protnum.h:185
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to Protocol type.
Definition: nettype.h:250
Common macros and compiler attributes/pragmas configuration.
Protocol is TCP.
Definition: nettype.h:126
Protocol is 6LoWPAN.
Definition: nettype.h:68
Protocol is IPv6.
Definition: nettype.h:109
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:38
#define ETHERTYPE_CUSTOM
Custom ethertype.
Definition: ethertype.h:52
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
#define PROTNUM_IPV6_EXT_FRAG
Fragment Header for IPv6.
Definition: protnum.h:80
Protocol is ICMPv6.
Definition: nettype.h:115
#define PROTNUM_IPV6_EXT_DST
IPv6 Extension Header: Destination Options.
Definition: protnum.h:102
Protocol is CCN.
Definition: nettype.h:136
#define PROTNUM_IPV6
IPv6 encapsulation.
Definition: protnum.h:77
Not so much protocol but data type that is passed to network devices using the netdev interface...
Definition: nettype.h:59
Custom ethertype.
Definition: nettype.h:98