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 GNRC_NETTYPE_H
26 #define 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_IPV6
65 #endif
66 #ifdef MODULE_GNRC_IPV6_EXT
67  GNRC_NETTYPE_IPV6_EXT,
68 #endif
69 #ifdef MODULE_GNRC_ICMPV6
71 #endif
72 
80 #ifdef MODULE_GNRC_TCP
81  GNRC_NETTYPE_TCP,
82 #endif
83 #ifdef MODULE_GNRC_UDP
85 #endif
86 
90 #ifdef MODULE_CCN_LITE
91  GNRC_NETTYPE_CCN,
92  GNRC_NETTYPE_CCN_CHUNK,
94 #endif
95 
100 #ifdef TEST_SUITES
101  GNRC_NETTYPE_TEST,
102 #endif
103 
109 
121 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
122 {
123  switch (type) {
124 #ifdef MODULE_GNRC_IPV6
125  case ETHERTYPE_IPV6:
126  return GNRC_NETTYPE_IPV6;
127 #endif
128 #ifdef MODULE_CCN_LITE
129  case ETHERTYPE_NDN:
130  return GNRC_NETTYPE_CCN;
131 #endif
132  default:
133  return GNRC_NETTYPE_UNDEF;
134  }
135 }
136 
148 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
149 {
150  switch (type) {
151 #ifdef MODULE_GNRC_IPV6
152  case GNRC_NETTYPE_IPV6:
153  return ETHERTYPE_IPV6;
154 #endif
155 #ifdef MODULE_CCN_LITE
156  case GNRC_NETTYPE_CCN:
157  return ETHERTYPE_NDN;
158 #endif
159  default:
160  return ETHERTYPE_UNKNOWN;
161  }
162 }
163 
175 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
176 {
177  switch (num) {
178 #ifdef MODULE_GNRC_ICMPV6
179  case PROTNUM_ICMPV6:
180  return GNRC_NETTYPE_ICMPV6;
181 #endif
182 #ifdef MODULE_GNRC_IPV6
183  case PROTNUM_IPV6:
184  return GNRC_NETTYPE_IPV6;
185 #endif
186 #ifdef MODULE_GNRC_TCP
187  case PROTNUM_TCP:
188  return GNRC_NETTYPE_TCP;
189 #endif
190 #ifdef MODULE_GNRC_UDP
191  case PROTNUM_UDP:
192  return GNRC_NETTYPE_UDP;
193 #endif
194 #ifdef MODULE_GNRC_IPV6_EXT
197  case PROTNUM_IPV6_EXT_RH:
199  case PROTNUM_IPV6_EXT_AH:
202  return GNRC_NETTYPE_IPV6_EXT;
203 #endif
204  default:
205  return GNRC_NETTYPE_UNDEF;
206  }
207 }
208 
220 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
221 {
222  switch (type) {
223 #ifdef MODULE_GNRC_ICMPV6
224  case GNRC_NETTYPE_ICMPV6:
225  return PROTNUM_ICMPV6;
226 #endif
227 #ifdef MODULE_GNRC_IPV6
228  case GNRC_NETTYPE_IPV6:
229  return PROTNUM_IPV6;
230 #endif
231 #ifdef MODULE_GNRC_TCP
232  case GNRC_NETTYPE_TCP:
233  return PROTNUM_TCP;
234 #endif
235 #ifdef MODULE_GNRC_UDP
236  case GNRC_NETTYPE_UDP:
237  return PROTNUM_UDP;
238 #endif
239  default:
240  return PROTNUM_RESERVED;
241  }
242 }
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif /* GNRC_NETTYPE_H */
249 
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:220
#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:148
#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:121
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:86
Protocol is UDP.
Definition: nettype.h:84
#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:107
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:175
Protocol is 6LoWPAN.
Definition: nettype.h:56
Protocol is IPv6.
Definition: nettype.h:64
#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:70
#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