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 
33 #ifndef NET_GNRC_NETTYPE_H
34 #define NET_GNRC_NETTYPE_H
35 
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_GOMACH) || defined(DOXYGEN)
70 #endif
71 #if IS_USED(MODULE_GNRC_NETTYPE_LWMAC) || defined(DOXYGEN)
73 #endif
74 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM) || defined(DOXYGEN)
76 #endif
79 #if IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN) || defined(DOXYGEN)
81 #endif
82 
83 #if IS_USED(MODULE_GNRC_NETTYPE_LORAWAN) || defined(DOXYGEN)
85 #endif
86 
91 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6) || defined(DOXYGEN)
93 #endif
94 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT) || defined(DOXYGEN)
96 #endif
97 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6) || defined(DOXYGEN)
99 #endif
100 
101 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || defined(DOXYGEN)
105 #endif
106 
107 #if IS_USED(MODULE_GNRC_NETTYPE_NDN) || defined(DOXYGEN)
109 #endif
116 #if IS_USED(MODULE_GNRC_NETTYPE_TCP) || defined(DOXYGEN)
118 #endif
119 #if IS_USED(MODULE_GNRC_NETTYPE_UDP) || defined(DOXYGEN)
121 #endif
128 #ifdef TEST_SUITES
130 #endif
135 
145 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
146 {
147  switch (type) {
148 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
149  case ETHERTYPE_IPV6:
150  return GNRC_NETTYPE_IPV6;
151 #endif
152 #if IS_USED(MODULE_GNRC_NETTYPE_CCN) || IS_USED(MODULE_GNRC_NETTYPE_NDN)
153  case ETHERTYPE_NDN:
154 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
155  return GNRC_NETTYPE_CCN;
156 #elif IS_USED(MODULE_GNRC_NETTYPE_NDN)
157  return GNRC_NETTYPE_NDN;
158 #endif
159 #endif
160 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
161  case ETHERTYPE_6LOENC:
162  return GNRC_NETTYPE_SIXLOWPAN;
163 #endif
164 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
165  case ETHERTYPE_CUSTOM:
166  return GNRC_NETTYPE_CUSTOM;
167 #endif
168  default:
169  return GNRC_NETTYPE_UNDEF;
170  }
171 }
172 
182 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
183 {
184  switch (type) {
185 #if IS_USED(MODULE_GNRC_NETTYPE_CUSTOM)
186  case GNRC_NETTYPE_CUSTOM:
187  return ETHERTYPE_CUSTOM;
188 #endif
189 #if IS_USED(MODULE_GNRC_SIXLOENC) && IS_USED(MODULE_GNRC_NETTYPE_SIXLOWPAN)
191  return ETHERTYPE_6LOENC;
192 #endif
193 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
194  case GNRC_NETTYPE_IPV6:
195  return ETHERTYPE_IPV6;
196 #endif
197 #if IS_USED(MODULE_GNRC_NETTYPE_CCN)
198  case GNRC_NETTYPE_CCN:
199  return ETHERTYPE_NDN;
200 #endif
201 #if IS_USED(MODULE_GNRC_NETTYPE_NDN)
202  case GNRC_NETTYPE_NDN:
203  return ETHERTYPE_NDN;
204 #endif
205  default:
206  return ETHERTYPE_UNKNOWN;
207  }
208 }
209 
221 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
222 {
223  switch (num) {
224 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
225  case PROTNUM_ICMPV6:
226  return GNRC_NETTYPE_ICMPV6;
227 #endif
228 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
229  case PROTNUM_IPV6:
230  return GNRC_NETTYPE_IPV6;
231 #endif
232 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
233  case PROTNUM_TCP:
234  return GNRC_NETTYPE_TCP;
235 #endif
236 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
237  case PROTNUM_UDP:
238  return GNRC_NETTYPE_UDP;
239 #endif
240 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6_EXT)
243  case PROTNUM_IPV6_EXT_RH:
245  case PROTNUM_IPV6_EXT_AH:
248  return GNRC_NETTYPE_IPV6_EXT;
249 #endif
250  default:
251  return GNRC_NETTYPE_UNDEF;
252  }
253 }
254 
266 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
267 {
268  switch (type) {
269 #if IS_USED(MODULE_GNRC_NETTYPE_IPV6)
270  case GNRC_NETTYPE_IPV6:
271  return PROTNUM_IPV6;
272 #endif
273 #if IS_USED(MODULE_GNRC_NETTYPE_ICMPV6)
274  case GNRC_NETTYPE_ICMPV6:
275  return PROTNUM_ICMPV6;
276 #endif
277 #if IS_USED(MODULE_GNRC_NETTYPE_TCP)
278  case GNRC_NETTYPE_TCP:
279  return PROTNUM_TCP;
280 #endif
281 #if IS_USED(MODULE_GNRC_NETTYPE_UDP)
282  case GNRC_NETTYPE_UDP:
283  return PROTNUM_UDP;
284 #endif
285  default:
286  return PROTNUM_RESERVED;
287  }
288 }
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #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:51
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to gnrc_nettype_t.
Definition: nettype.h:145
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates gnrc_nettype_t to a Protocol Number.
Definition: nettype.h:266
static gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
Translates a Protocol Number to gnrc_nettype_t.
Definition: nettype.h:221
static uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
Translates gnrc_nettype_t to an Ether Type number.
Definition: nettype.h:182
@ GNRC_NETTYPE_LORAWAN
Protocol is LoRaWAN.
Definition: nettype.h:84
@ 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:95
@ GNRC_NETTYPE_CCN_CHUNK
Protocol is CCN, packet contains a content chunk.
Definition: nettype.h:103
@ GNRC_NETTYPE_CCN
Protocol is CCN.
Definition: nettype.h:102
@ GNRC_NETTYPE_CUSTOM
Custom ethertype.
Definition: nettype.h:75
@ GNRC_NETTYPE_TEST
Usable with test vectors.
Definition: nettype.h:129
@ 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:92
@ GNRC_NETTYPE_LWMAC
Protocol is lwMAC.
Definition: nettype.h:72
@ GNRC_NETTYPE_UDP
Protocol is UDP.
Definition: nettype.h:120
@ GNRC_NETTYPE_UNDEF
Protocol is undefined.
Definition: nettype.h:62
@ GNRC_NETTYPE_ICMPV6
Protocol is ICMPv6.
Definition: nettype.h:98
@ GNRC_NETTYPE_GOMACH
Protocol is GoMacH.
Definition: nettype.h:69
@ GNRC_NETTYPE_SIXLOWPAN
Protocol is 6LoWPAN.
Definition: nettype.h:80
@ GNRC_NETTYPE_TCP
Protocol is TCP.
Definition: nettype.h:117
@ GNRC_NETTYPE_NDN
Protocol is NDN.
Definition: nettype.h:108
@ GNRC_NETTYPE_NUMOF
maximum number of available protocols
Definition: nettype.h:133
#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.