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 
9 #pragma once
10 
36 #include <inttypes.h>
37 
38 #include "modules.h"
39 #include "net/ethertype.h"
40 #include "net/protnum.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
51 typedef enum {
68 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
70 #endif
73 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
75 #endif
76 
77 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
83 #define GNRC_NETTYPE_LORAWAN GNRC_NETTYPE_UNDEF
84 #endif
85 
90 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
92 #endif
93 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
95 #endif
96 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
98 #endif
99 
100 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
104 #endif
105 
106 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
108 #endif
115 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
117 #endif
118 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
120 #endif
127 #ifdef TEST_SUITES
129 #endif
134 
144 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
145 {
146  switch (type) {
147 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
148  case ETHERTYPE_IPV6:
149  return GNRC_NETTYPE_IPV6;
150 #endif
151 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
152  case ETHERTYPE_NDN:
153 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
154  return GNRC_NETTYPE_CCN;
155 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
156  return GNRC_NETTYPE_NDN;
157 #endif
158 #endif
159 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
160  case ETHERTYPE_6LOENC:
161  return GNRC_NETTYPE_SIXLOWPAN;
162 #endif
163 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
164  case ETHERTYPE_CUSTOM:
165  return GNRC_NETTYPE_CUSTOM;
166 #endif
167  default:
168  return GNRC_NETTYPE_UNDEF;
169  }
170 }
171 
181 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
182 {
183  switch (type) {
184 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
185  case GNRC_NETTYPE_CUSTOM:
186  return ETHERTYPE_CUSTOM;
187 #endif
188 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
190  return ETHERTYPE_6LOENC;
191 #endif
192 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
193  case GNRC_NETTYPE_IPV6:
194  return ETHERTYPE_IPV6;
195 #endif
196 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
197  case GNRC_NETTYPE_CCN:
198  return ETHERTYPE_NDN;
199 #endif
200 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
201  case GNRC_NETTYPE_NDN:
202  return ETHERTYPE_NDN;
203 #endif
204  default:
205  return ETHERTYPE_UNKNOWN;
206  }
207 }
208 
220 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
221 {
222  switch (num) {
223 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
224  case PROTNUM_ICMPV6:
225  return GNRC_NETTYPE_ICMPV6;
226 #endif
227 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
228  case PROTNUM_IPV6:
229  return GNRC_NETTYPE_IPV6;
230 #endif
231 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
232  case PROTNUM_TCP:
233  return GNRC_NETTYPE_TCP;
234 #endif
235 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
236  case PROTNUM_UDP:
237  return GNRC_NETTYPE_UDP;
238 #endif
239 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
242  case PROTNUM_IPV6_EXT_RH:
244  case PROTNUM_IPV6_EXT_AH:
247  return GNRC_NETTYPE_IPV6_EXT;
248 #endif
249  default:
250  return GNRC_NETTYPE_UNDEF;
251  }
252 }
253 
265 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
266 {
267  switch (type) {
268 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
269  case GNRC_NETTYPE_IPV6:
270  return PROTNUM_IPV6;
271 #endif
272 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
273  case GNRC_NETTYPE_ICMPV6:
274  return PROTNUM_ICMPV6;
275 #endif
276 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
277  case GNRC_NETTYPE_TCP:
278  return PROTNUM_TCP;
279 #endif
280 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
281  case GNRC_NETTYPE_UDP:
282  return PROTNUM_UDP;
283 #endif
284  default:
285  return PROTNUM_RESERVED;
286  }
287 }
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
Ether type definitions.
#define ETHERTYPE_CUSTOM
Custom ethertype.
Definition: ethertype.h:50
#define ETHERTYPE_6LOENC
6LoWPAN encapsulation
Definition: ethertype.h:38
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:37
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:56
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:36
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:51
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to gnrc_nettype_t.
Definition: nettype.h:144
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates gnrc_nettype_t to a Protocol Number.
Definition: nettype.h:265
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to gnrc_nettype_t.
Definition: nettype.h:220
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates gnrc_nettype_t to an Ether Type number.
Definition: nettype.h:181
@ GNRC_NETTYPE_TX_SYNC
TX synchronization data for passing up error data or auxiliary data.
Definition: nettype.h:56
@ GNRC_NETTYPE_IPV6_EXT
Protocol is IPv6 extension header.
Definition: nettype.h:94
@ GNRC_NETTYPE_CCN_CHUNK
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:102
@ GNRC_NETTYPE_CCN
Protocol is CCN.
Definition: nettype.h:101
@ GNRC_NETTYPE_CUSTOM
Custom ethertype.
Definition: nettype.h:69
@ GNRC_NETTYPE_TEST
Usable with test vectors.
Definition: nettype.h:128
@ GNRC_NETTYPE_NETIF
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:61
@ GNRC_NETTYPE_IPV6
Protocol is IPv6.
Definition: nettype.h:91
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition: nettype.h:119
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition: nettype.h:62
@ GNRC_NETTYPE_ICMPV6
Protocol is ICMPv6.
Definition: nettype.h:97
@ GNRC_NETTYPE_SIXLOWPAN
Protocol is 6LoWPAN.
Definition: nettype.h:74
@ GNRC_NETTYPE_TCP
Protocol is TCP.
Definition: nettype.h:116
@ GNRC_NETTYPE_NDN
Protocol is NDN.
Definition: nettype.h:107
@ GNRC_NETTYPE_NUMOF
maximum number of available protocols
Definition: nettype.h:132
#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.