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 {
63 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
65 #endif
66 
71 #if IS_USED(MODULE_GNRC_NETTYPE_GOMACH) || defined(DOXYGEN)
73 #endif
82 #if IS_USED(MODULE_GNRC_NETTYPE_LWMAC) || defined(DOXYGEN)
84 #endif
93 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
95 #endif
104 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
106 #endif
107 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
109 #endif
110 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
112 #endif
121 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
123 #endif
124 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
126 #endif
131 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
135 #endif
136 
137 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
139 #endif
140 
141 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
143 #endif
144 
149 #ifdef TEST_SUITES
150  GNRC_NETTYPE_TEST,
151 #endif
158 
169 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
170 {
171  switch (type) {
172 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
173  case ETHERTYPE_IPV6:
174  return GNRC_NETTYPE_IPV6;
175 #endif
176 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
177  case ETHERTYPE_NDN:
178 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
179  return GNRC_NETTYPE_CCN;
180 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
181  return GNRC_NETTYPE_NDN;
182 #endif
183 #endif
184 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
185  case ETHERTYPE_6LOENC:
186  return GNRC_NETTYPE_SIXLOWPAN;
187 #endif
188 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
189  case ETHERTYPE_CUSTOM:
190  return GNRC_NETTYPE_CUSTOM;
191 #endif
192  default:
193  return GNRC_NETTYPE_UNDEF;
194  }
195 }
196 
207 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
208 {
209  switch (type) {
210 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
212  return ETHERTYPE_6LOENC;
213 #endif
214 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
215  case GNRC_NETTYPE_IPV6:
216  return ETHERTYPE_IPV6;
217 #endif
218 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
219  case GNRC_NETTYPE_CCN:
220  return ETHERTYPE_NDN;
221 #endif
222 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
223  case GNRC_NETTYPE_NDN:
224  return ETHERTYPE_NDN;
225 #endif
226 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
227  case GNRC_NETTYPE_CUSTOM:
228  return ETHERTYPE_CUSTOM;
229 #endif
230  default:
231  return ETHERTYPE_UNKNOWN;
232  }
233 }
234 
246 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
247 {
248  switch (num) {
249 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
250  case PROTNUM_ICMPV6:
251  return GNRC_NETTYPE_ICMPV6;
252 #endif
253 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
254  case PROTNUM_IPV6:
255  return GNRC_NETTYPE_IPV6;
256 #endif
257 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
258  case PROTNUM_TCP:
259  return GNRC_NETTYPE_TCP;
260 #endif
261 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
262  case PROTNUM_UDP:
263  return GNRC_NETTYPE_UDP;
264 #endif
265 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
268  case PROTNUM_IPV6_EXT_RH:
270  case PROTNUM_IPV6_EXT_AH:
273  return GNRC_NETTYPE_IPV6_EXT;
274 #endif
275  default:
276  return GNRC_NETTYPE_UNDEF;
277  }
278 }
279 
291 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
292 {
293  switch (type) {
294 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
295  case GNRC_NETTYPE_ICMPV6:
296  return PROTNUM_ICMPV6;
297 #endif
298 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
299  case GNRC_NETTYPE_IPV6:
300  return PROTNUM_IPV6;
301 #endif
302 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
303  case GNRC_NETTYPE_TCP:
304  return PROTNUM_TCP;
305 #endif
306 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
307  case GNRC_NETTYPE_UDP:
308  return PROTNUM_UDP;
309 #endif
310  default:
311  return PROTNUM_RESERVED;
312  }
313 }
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 
319 #endif /* NET_GNRC_NETTYPE_H */
Ether type definitions.
#define ETHERTYPE_CUSTOM
Custom ethertype.
Definition: ethertype.h:51
#define ETHERTYPE_6LOENC
6LoWPAN encapsulation
Definition: ethertype.h:39
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:38
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:57
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:37
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to Protocol type.
Definition: nettype.h:169
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:291
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to Protocol type.
Definition: nettype.h:246
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates Protocol type to an Ether Type number.
Definition: nettype.h:207
@ GNRC_NETTYPE_LORAWAN
Protocol is LoRaWAN.
Definition: nettype.h:142
@ GNRC_NETTYPE_TX_SYNC
TX synchronization data for passing up error data or auxiliary data.
Definition: nettype.h:55
@ GNRC_NETTYPE_IPV6_EXT
Protocol is IPv6 extension header.
Definition: nettype.h:108
@ GNRC_NETTYPE_CCN_CHUNK
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:133
@ GNRC_NETTYPE_CCN
Protocol is CCN.
Definition: nettype.h:132
@ GNRC_NETTYPE_CUSTOM
Custom ethertype.
Definition: nettype.h:94
@ GNRC_NETTYPE_NETIF
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:60
@ GNRC_NETTYPE_IPV6
Protocol is IPv6.
Definition: nettype.h:105
@ GNRC_NETTYPE_LWMAC
Protocol is lwMAC.
Definition: nettype.h:83
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition: nettype.h:125
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition: nettype.h:61
@ GNRC_NETTYPE_ICMPV6
Protocol is ICMPv6.
Definition: nettype.h:111
@ GNRC_NETTYPE_GOMACH
Protocol is GoMacH.
Definition: nettype.h:72
@ GNRC_NETTYPE_SIXLOWPAN
Protocol is 6LoWPAN.
Definition: nettype.h:64
@ GNRC_NETTYPE_TCP
Protocol is TCP.
Definition: nettype.h:122
@ GNRC_NETTYPE_NDN
Protocol is NDN.
Definition: nettype.h:138
@ GNRC_NETTYPE_NUMOF
maximum number of available protocols
Definition: nettype.h:156
#define PROTNUM_IPV6_EXT_MOB
IPv6 Mobility Extension Header.
Definition: protnum.h:170
#define PROTNUM_IPV6_EXT_HOPOPT
IPv6 Hop-by-Hop Option.
Definition: protnum.h:33
#define PROTNUM_IPV6_EXT_FRAG
Fragment Header for IPv6.
Definition: protnum.h:78
#define PROTNUM_RESERVED
Reserved.
Definition: protnum.h:178
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:84
#define PROTNUM_ICMPV6
ICMP for IPv6.
Definition: protnum.h:95
#define PROTNUM_IPV6_EXT_DST
IPv6 Extension Header: Destination Options.
Definition: protnum.h:97
#define PROTNUM_IPV6
IPv6 encapsulation.
Definition: protnum.h:75
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:51
#define PROTNUM_IPV6_EXT_AH
IPv6 Authentication Extension Header.
Definition: protnum.h:86
#define PROTNUM_TCP
Transmission Control.
Definition: protnum.h:39
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:77
Adds include for missing inttype definitions.
Common macros and compiler attributes/pragmas configuration.
Protocol number definitions.