nettype.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
33 #include <inttypes.h>
34 
35 #include "modules.h"
36 #include "net/ethertype.h"
37 #include "net/protnum.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
48 typedef enum {
65 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
67 #endif
70 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
72 #endif
73 
74 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
80 #define GNRC_NETTYPE_LORAWAN GNRC_NETTYPE_UNDEF
81 #endif
82 
87 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
89 #endif
90 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
92 #endif
93 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
95 #endif
96 
97 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
101 #endif
102 
103 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
105 #endif
112 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
114 #endif
115 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
117 #endif
124 #ifdef TEST_SUITES
126 #endif
131 
141 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
142 {
143  switch (type) {
144 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
145  case ETHERTYPE_IPV6:
146  return GNRC_NETTYPE_IPV6;
147 #endif
148 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
149  case ETHERTYPE_NDN:
150 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
151  return GNRC_NETTYPE_CCN;
152 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
153  return GNRC_NETTYPE_NDN;
154 #endif
155 #endif
156 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
157  case ETHERTYPE_6LOENC:
158  return GNRC_NETTYPE_SIXLOWPAN;
159 #endif
160 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
161  case ETHERTYPE_CUSTOM:
162  return GNRC_NETTYPE_CUSTOM;
163 #endif
164  default:
165  return GNRC_NETTYPE_UNDEF;
166  }
167 }
168 
178 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
179 {
180  switch (type) {
181 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
182  case GNRC_NETTYPE_CUSTOM:
183  return ETHERTYPE_CUSTOM;
184 #endif
185 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
187  return ETHERTYPE_6LOENC;
188 #endif
189 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
190  case GNRC_NETTYPE_IPV6:
191  return ETHERTYPE_IPV6;
192 #endif
193 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
194  case GNRC_NETTYPE_CCN:
195  return ETHERTYPE_NDN;
196 #endif
197 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
198  case GNRC_NETTYPE_NDN:
199  return ETHERTYPE_NDN;
200 #endif
201  default:
202  return ETHERTYPE_UNKNOWN;
203  }
204 }
205 
217 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
218 {
219  switch (num) {
220 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
221  case PROTNUM_ICMPV6:
222  return GNRC_NETTYPE_ICMPV6;
223 #endif
224 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
225  case PROTNUM_IPV6:
226  return GNRC_NETTYPE_IPV6;
227 #endif
228 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
229  case PROTNUM_TCP:
230  return GNRC_NETTYPE_TCP;
231 #endif
232 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
233  case PROTNUM_UDP:
234  return GNRC_NETTYPE_UDP;
235 #endif
236 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
239  case PROTNUM_IPV6_EXT_RH:
241  case PROTNUM_IPV6_EXT_AH:
244  return GNRC_NETTYPE_IPV6_EXT;
245 #endif
246  default:
247  return GNRC_NETTYPE_UNDEF;
248  }
249 }
250 
262 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
263 {
264  switch (type) {
265 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
266  case GNRC_NETTYPE_IPV6:
267  return PROTNUM_IPV6;
268 #endif
269 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
270  case GNRC_NETTYPE_ICMPV6:
271  return PROTNUM_ICMPV6;
272 #endif
273 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
274  case GNRC_NETTYPE_TCP:
275  return PROTNUM_TCP;
276 #endif
277 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
278  case GNRC_NETTYPE_UDP:
279  return PROTNUM_UDP;
280 #endif
281  default:
282  return PROTNUM_RESERVED;
283  }
284 }
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
Ether type definitions.
#define ETHERTYPE_CUSTOM
Custom ethertype.
Definition: ethertype.h:47
#define ETHERTYPE_6LOENC
6LoWPAN encapsulation
Definition: ethertype.h:35
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:34
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:53
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:33
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:48
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to gnrc_nettype_t.
Definition: nettype.h:141
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates gnrc_nettype_t to a Protocol Number.
Definition: nettype.h:262
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to gnrc_nettype_t.
Definition: nettype.h:217
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates gnrc_nettype_t to an Ether Type number.
Definition: nettype.h:178
@ GNRC_NETTYPE_TX_SYNC
TX synchronization data for passing up error data or auxiliary data.
Definition: nettype.h:53
@ GNRC_NETTYPE_IPV6_EXT
Protocol is IPv6 extension header.
Definition: nettype.h:91
@ GNRC_NETTYPE_CCN_CHUNK
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:99
@ GNRC_NETTYPE_CCN
Protocol is CCN.
Definition: nettype.h:98
@ GNRC_NETTYPE_CUSTOM
Custom ethertype.
Definition: nettype.h:66
@ GNRC_NETTYPE_TEST
Usable with test vectors.
Definition: nettype.h:125
@ GNRC_NETTYPE_NETIF
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:58
@ GNRC_NETTYPE_IPV6
Protocol is IPv6.
Definition: nettype.h:88
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition: nettype.h:116
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition: nettype.h:59
@ GNRC_NETTYPE_ICMPV6
Protocol is ICMPv6.
Definition: nettype.h:94
@ GNRC_NETTYPE_SIXLOWPAN
Protocol is 6LoWPAN.
Definition: nettype.h:71
@ GNRC_NETTYPE_TCP
Protocol is TCP.
Definition: nettype.h:113
@ GNRC_NETTYPE_NDN
Protocol is NDN.
Definition: nettype.h:104
@ GNRC_NETTYPE_NUMOF
maximum number of available protocols
Definition: nettype.h:129
#define PROTNUM_IPV6_EXT_MOB
IPv6 Mobility Extension Header.
Definition: protnum.h:167
#define PROTNUM_IPV6_EXT_HOPOPT
IPv6 Hop-by-Hop Option.
Definition: protnum.h:30
#define PROTNUM_IPV6_EXT_FRAG
Fragment Header for IPv6.
Definition: protnum.h:75
#define PROTNUM_RESERVED
Reserved.
Definition: protnum.h:175
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:81
#define PROTNUM_ICMPV6
ICMP for IPv6.
Definition: protnum.h:92
#define PROTNUM_IPV6_EXT_DST
IPv6 Extension Header: Destination Options.
Definition: protnum.h:94
#define PROTNUM_IPV6
IPv6 encapsulation.
Definition: protnum.h:72
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:48
#define PROTNUM_IPV6_EXT_AH
IPv6 Authentication Extension Header.
Definition: protnum.h:83
#define PROTNUM_TCP
Transmission Control.
Definition: protnum.h:36
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:74
Adds include for missing inttype definitions.
Common macros and compiler attributes/pragmas configuration.
Protocol number definitions.