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 
25 #ifndef NET_GNRC_NETTYPE_H
26 #define NET_GNRC_NETTYPE_H
27 
28 #include <inttypes.h>
29 
30 #include "net/ethertype.h"
31 #include "net/protnum.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
42 typedef enum {
59 #ifdef MODULE_GNRC_SIXLOWPAN
61 #endif
62 
67 #ifdef MODULE_GNRC_GOMACH
68  GNRC_NETTYPE_GOMACH,
69 #endif
70 
78 #ifdef MODULE_GNRC_LWMAC
79  GNRC_NETTYPE_LWMAC,
80 #endif
81 
89 #ifdef MODULE_GNRC_IPV6
91 #endif
92 #ifdef MODULE_GNRC_IPV6_EXT
93  GNRC_NETTYPE_IPV6_EXT,
94 #endif
95 #ifdef MODULE_GNRC_ICMPV6
97 #endif
98 
106 #ifdef MODULE_GNRC_TCP
107  GNRC_NETTYPE_TCP,
108 #endif
109 #ifdef MODULE_GNRC_UDP
111 #endif
112 
116 #ifdef MODULE_CCN_LITE
117  GNRC_NETTYPE_CCN,
118  GNRC_NETTYPE_CCN_CHUNK,
120 #endif
121 
122 #ifdef MODULE_NDN_RIOT
123  GNRC_NETTYPE_NDN,
124 #endif
125 
126 #ifdef MODULE_GNRC_LORAWAN
127  GNRC_NETTYPE_LORAWAN,
128 #endif
129 
134 #ifdef TEST_SUITES
135  GNRC_NETTYPE_TEST,
136 #endif
137 
143 
155 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
156 {
157  switch (type) {
158 #ifdef MODULE_GNRC_IPV6
159  case ETHERTYPE_IPV6:
160  return GNRC_NETTYPE_IPV6;
161 #endif
162 #if defined(MODULE_CCN_LITE) || defined(MODULE_NDN_RIOT)
163  case ETHERTYPE_NDN:
164 #if defined(MODULE_CCN_LITE)
165  return GNRC_NETTYPE_CCN;
166 #elif defined(MODULE_NDN_RIOT)
167  return GNRC_NETTYPE_NDN;
168 #endif
169 #endif
170 #ifdef MODULE_GNRC_SIXLOENC
171  case ETHERTYPE_6LOENC:
172  return GNRC_NETTYPE_SIXLOWPAN;
173 #endif
174  default:
175  return GNRC_NETTYPE_UNDEF;
176  }
177 }
178 
190 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
191 {
192  switch (type) {
193 #ifdef MODULE_GNRC_SIXLOENC
195  return ETHERTYPE_6LOENC;
196 #endif
197 #ifdef MODULE_GNRC_IPV6
198  case GNRC_NETTYPE_IPV6:
199  return ETHERTYPE_IPV6;
200 #endif
201 #ifdef MODULE_CCN_LITE
202  case GNRC_NETTYPE_CCN:
203  return ETHERTYPE_NDN;
204 #endif
205 #ifdef MODULE_NDN_RIOT
206  case GNRC_NETTYPE_NDN:
207  return ETHERTYPE_NDN;
208 #endif
209  default:
210  return ETHERTYPE_UNKNOWN;
211  }
212 }
213 
225 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
226 {
227  switch (num) {
228 #ifdef MODULE_GNRC_ICMPV6
229  case PROTNUM_ICMPV6:
230  return GNRC_NETTYPE_ICMPV6;
231 #endif
232 #ifdef MODULE_GNRC_IPV6
233  case PROTNUM_IPV6:
234  return GNRC_NETTYPE_IPV6;
235 #endif
236 #ifdef MODULE_GNRC_TCP
237  case PROTNUM_TCP:
238  return GNRC_NETTYPE_TCP;
239 #endif
240 #ifdef MODULE_GNRC_UDP
241  case PROTNUM_UDP:
242  return GNRC_NETTYPE_UDP;
243 #endif
244 #ifdef MODULE_GNRC_IPV6_EXT
247  case PROTNUM_IPV6_EXT_RH:
249  case PROTNUM_IPV6_EXT_AH:
252  return GNRC_NETTYPE_IPV6_EXT;
253 #endif
254  default:
255  return GNRC_NETTYPE_UNDEF;
256  }
257 }
258 
270 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
271 {
272  switch (type) {
273 #ifdef MODULE_GNRC_ICMPV6
274  case GNRC_NETTYPE_ICMPV6:
275  return PROTNUM_ICMPV6;
276 #endif
277 #ifdef MODULE_GNRC_IPV6
278  case GNRC_NETTYPE_IPV6:
279  return PROTNUM_IPV6;
280 #endif
281 #ifdef MODULE_GNRC_TCP
282  case GNRC_NETTYPE_TCP:
283  return PROTNUM_TCP;
284 #endif
285 #ifdef MODULE_GNRC_UDP
286  case GNRC_NETTYPE_UDP:
287  return PROTNUM_UDP;
288 #endif
289  default:
290  return PROTNUM_RESERVED;
291  }
292 }
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif /* NET_GNRC_NETTYPE_H */
299 
Protocol number definitions.
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:39
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:41
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:270
#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:190
#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
static gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
Translates an Ether Type number to Protocol type.
Definition: nettype.h:155
#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 UDP.
Definition: nettype.h:110
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:79
Protocol is undefined.
Definition: nettype.h:57
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:56
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:53
maximum number of available protocols
Definition: nettype.h:141
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:225
Protocol is 6LoWPAN.
Definition: nettype.h:60
Protocol is IPv6.
Definition: nettype.h:90
#define ETHERTYPE_NDN
NDN Protocol (http://named-data.net/)
Definition: ethertype.h:38
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
#define PROTNUM_IPV6_EXT_FRAG
Fragment Header for IPv6.
Definition: protnum.h:80
Protocol is ICMPv6.
Definition: nettype.h:96
#define PROTNUM_IPV6_EXT_DST
IPv6 Extension Header: Destination Options.
Definition: protnum.h:102
#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:51