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 {
55 #ifdef MODULE_GNRC_SIXLOWPAN
57 #endif
58 
63 #ifdef MODULE_GNRC_GOMACH
64  GNRC_NETTYPE_GOMACH,
65 #endif
66 
74 #ifdef MODULE_GNRC_LWMAC
75  GNRC_NETTYPE_LWMAC,
76 #endif
77 
85 #ifdef MODULE_GNRC_IPV6
87 #endif
88 #ifdef MODULE_GNRC_IPV6_EXT
89  GNRC_NETTYPE_IPV6_EXT,
90 #endif
91 #ifdef MODULE_GNRC_ICMPV6
93 #endif
94 
102 #ifdef MODULE_GNRC_TCP
103  GNRC_NETTYPE_TCP,
104 #endif
105 #ifdef MODULE_GNRC_UDP
107 #endif
108 
112 #ifdef MODULE_CCN_LITE
113  GNRC_NETTYPE_CCN,
114  GNRC_NETTYPE_CCN_CHUNK,
116 #endif
117 
118 #ifdef MODULE_NDN_RIOT
119  GNRC_NETTYPE_NDN,
120 #endif
121 
126 #ifdef TEST_SUITES
127  GNRC_NETTYPE_TEST,
128 #endif
129 
135 
147 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
148 {
149  switch (type) {
150 #ifdef MODULE_GNRC_IPV6
151  case ETHERTYPE_IPV6:
152  return GNRC_NETTYPE_IPV6;
153 #endif
154 #if defined(MODULE_CCN_LITE) || defined(MODULE_NDN_RIOT)
155  case ETHERTYPE_NDN:
156 #if defined(MODULE_CCN_LITE)
157  return GNRC_NETTYPE_CCN;
158 #elif defined(MODULE_NDN_RIOT)
159  return GNRC_NETTYPE_NDN;
160 #endif
161 #endif
162  default:
163  return GNRC_NETTYPE_UNDEF;
164  }
165 }
166 
178 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
179 {
180  switch (type) {
181 #ifdef MODULE_GNRC_IPV6
182  case GNRC_NETTYPE_IPV6:
183  return ETHERTYPE_IPV6;
184 #endif
185 #ifdef MODULE_CCN_LITE
186  case GNRC_NETTYPE_CCN:
187  return ETHERTYPE_NDN;
188 #endif
189 #ifdef MODULE_NDN_RIOT
190  case GNRC_NETTYPE_NDN:
191  return ETHERTYPE_NDN;
192 #endif
193  default:
194  return ETHERTYPE_UNKNOWN;
195  }
196 }
197 
209 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
210 {
211  switch (num) {
212 #ifdef MODULE_GNRC_ICMPV6
213  case PROTNUM_ICMPV6:
214  return GNRC_NETTYPE_ICMPV6;
215 #endif
216 #ifdef MODULE_GNRC_IPV6
217  case PROTNUM_IPV6:
218  return GNRC_NETTYPE_IPV6;
219 #endif
220 #ifdef MODULE_GNRC_TCP
221  case PROTNUM_TCP:
222  return GNRC_NETTYPE_TCP;
223 #endif
224 #ifdef MODULE_GNRC_UDP
225  case PROTNUM_UDP:
226  return GNRC_NETTYPE_UDP;
227 #endif
228 #ifdef MODULE_GNRC_IPV6_EXT
231  case PROTNUM_IPV6_EXT_RH:
233  case PROTNUM_IPV6_EXT_AH:
236  return GNRC_NETTYPE_IPV6_EXT;
237 #endif
238  default:
239  return GNRC_NETTYPE_UNDEF;
240  }
241 }
242 
254 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
255 {
256  switch (type) {
257 #ifdef MODULE_GNRC_ICMPV6
258  case GNRC_NETTYPE_ICMPV6:
259  return PROTNUM_ICMPV6;
260 #endif
261 #ifdef MODULE_GNRC_IPV6
262  case GNRC_NETTYPE_IPV6:
263  return PROTNUM_IPV6;
264 #endif
265 #ifdef MODULE_GNRC_TCP
266  case GNRC_NETTYPE_TCP:
267  return PROTNUM_TCP;
268 #endif
269 #ifdef MODULE_GNRC_UDP
270  case GNRC_NETTYPE_UDP:
271  return PROTNUM_UDP;
272 #endif
273  default:
274  return PROTNUM_RESERVED;
275  }
276 }
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif /* NET_GNRC_NETTYPE_H */
283 
Protocol number definitions.
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:39
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:40
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:254
#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:178
#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:147
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:86
Protocol is UDP.
Definition: nettype.h:106
#define PROTNUM_IPV6_EXT_RH
Routing Header for IPv6.
Definition: protnum.h:79
Protocol is undefined.
Definition: nettype.h:53
Protocol is as defined in gnrc_netif_hdr_t.
Definition: nettype.h:52
#define PROTNUM_UDP
User Datagram.
Definition: protnum.h:53
maximum number of available protocols
Definition: nettype.h:133
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:209
Protocol is 6LoWPAN.
Definition: nettype.h:56
Protocol is IPv6.
Definition: nettype.h:86
#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:92
#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:47