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 
122 #ifdef TEST_SUITES
123  GNRC_NETTYPE_TEST,
124 #endif
125 
131 
143 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
144 {
145  switch (type) {
146 #ifdef MODULE_GNRC_IPV6
147  case ETHERTYPE_IPV6:
148  return GNRC_NETTYPE_IPV6;
149 #endif
150 #ifdef MODULE_CCN_LITE
151  case ETHERTYPE_NDN:
152  return GNRC_NETTYPE_CCN;
153 #endif
154  default:
155  return GNRC_NETTYPE_UNDEF;
156  }
157 }
158 
170 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
171 {
172  switch (type) {
173 #ifdef MODULE_GNRC_IPV6
174  case GNRC_NETTYPE_IPV6:
175  return ETHERTYPE_IPV6;
176 #endif
177 #ifdef MODULE_CCN_LITE
178  case GNRC_NETTYPE_CCN:
179  return ETHERTYPE_NDN;
180 #endif
181  default:
182  return ETHERTYPE_UNKNOWN;
183  }
184 }
185 
197 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
198 {
199  switch (num) {
200 #ifdef MODULE_GNRC_ICMPV6
201  case PROTNUM_ICMPV6:
202  return GNRC_NETTYPE_ICMPV6;
203 #endif
204 #ifdef MODULE_GNRC_IPV6
205  case PROTNUM_IPV6:
206  return GNRC_NETTYPE_IPV6;
207 #endif
208 #ifdef MODULE_GNRC_TCP
209  case PROTNUM_TCP:
210  return GNRC_NETTYPE_TCP;
211 #endif
212 #ifdef MODULE_GNRC_UDP
213  case PROTNUM_UDP:
214  return GNRC_NETTYPE_UDP;
215 #endif
216 #ifdef MODULE_GNRC_IPV6_EXT
219  case PROTNUM_IPV6_EXT_RH:
221  case PROTNUM_IPV6_EXT_AH:
224  return GNRC_NETTYPE_IPV6_EXT;
225 #endif
226  default:
227  return GNRC_NETTYPE_UNDEF;
228  }
229 }
230 
242 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
243 {
244  switch (type) {
245 #ifdef MODULE_GNRC_ICMPV6
246  case GNRC_NETTYPE_ICMPV6:
247  return PROTNUM_ICMPV6;
248 #endif
249 #ifdef MODULE_GNRC_IPV6
250  case GNRC_NETTYPE_IPV6:
251  return PROTNUM_IPV6;
252 #endif
253 #ifdef MODULE_GNRC_TCP
254  case GNRC_NETTYPE_TCP:
255  return PROTNUM_TCP;
256 #endif
257 #ifdef MODULE_GNRC_UDP
258  case GNRC_NETTYPE_UDP:
259  return PROTNUM_UDP;
260 #endif
261  default:
262  return PROTNUM_RESERVED;
263  }
264 }
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif /* NET_GNRC_NETTYPE_H */
271 
Protocol number definitions.
#define ETHERTYPE_IPV6
Internet protocol version 6.
Definition: ethertype.h:38
#define ETHERTYPE_UNKNOWN
Reserved (no protocol specified)
Definition: ethertype.h:39
static uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
Translates Protocol type to a Protocol Number.
Definition: nettype.h:242
#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:170
#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:143
#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:129
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:197
Protocol is 6LoWPAN.
Definition: nettype.h:56
Protocol is IPv6.
Definition: nettype.h:86
#define ETHERTYPE_NDN
Parc CCNX.
Definition: ethertype.h:37
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