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_LWMAC
64  GNRC_NETTYPE_LWMAC,
65 #endif
66 
74 #ifdef MODULE_GNRC_IPV6
76 #endif
77 #ifdef MODULE_GNRC_IPV6_EXT
78  GNRC_NETTYPE_IPV6_EXT,
79 #endif
80 #ifdef MODULE_GNRC_ICMPV6
82 #endif
83 
91 #ifdef MODULE_GNRC_TCP
92  GNRC_NETTYPE_TCP,
93 #endif
94 #ifdef MODULE_GNRC_UDP
96 #endif
97 
101 #ifdef MODULE_CCN_LITE
102  GNRC_NETTYPE_CCN,
103  GNRC_NETTYPE_CCN_CHUNK,
105 #endif
106 
111 #ifdef TEST_SUITES
112  GNRC_NETTYPE_TEST,
113 #endif
114 
120 
132 static inline gnrc_nettype_t gnrc_nettype_from_ethertype(uint16_t type)
133 {
134  switch (type) {
135 #ifdef MODULE_GNRC_IPV6
136  case ETHERTYPE_IPV6:
137  return GNRC_NETTYPE_IPV6;
138 #endif
139 #ifdef MODULE_CCN_LITE
140  case ETHERTYPE_NDN:
141  return GNRC_NETTYPE_CCN;
142 #endif
143  default:
144  return GNRC_NETTYPE_UNDEF;
145  }
146 }
147 
159 static inline uint16_t gnrc_nettype_to_ethertype(gnrc_nettype_t type)
160 {
161  switch (type) {
162 #ifdef MODULE_GNRC_IPV6
163  case GNRC_NETTYPE_IPV6:
164  return ETHERTYPE_IPV6;
165 #endif
166 #ifdef MODULE_CCN_LITE
167  case GNRC_NETTYPE_CCN:
168  return ETHERTYPE_NDN;
169 #endif
170  default:
171  return ETHERTYPE_UNKNOWN;
172  }
173 }
174 
186 static inline gnrc_nettype_t gnrc_nettype_from_protnum(uint8_t num)
187 {
188  switch (num) {
189 #ifdef MODULE_GNRC_ICMPV6
190  case PROTNUM_ICMPV6:
191  return GNRC_NETTYPE_ICMPV6;
192 #endif
193 #ifdef MODULE_GNRC_IPV6
194  case PROTNUM_IPV6:
195  return GNRC_NETTYPE_IPV6;
196 #endif
197 #ifdef MODULE_GNRC_TCP
198  case PROTNUM_TCP:
199  return GNRC_NETTYPE_TCP;
200 #endif
201 #ifdef MODULE_GNRC_UDP
202  case PROTNUM_UDP:
203  return GNRC_NETTYPE_UDP;
204 #endif
205 #ifdef MODULE_GNRC_IPV6_EXT
208  case PROTNUM_IPV6_EXT_RH:
210  case PROTNUM_IPV6_EXT_AH:
213  return GNRC_NETTYPE_IPV6_EXT;
214 #endif
215  default:
216  return GNRC_NETTYPE_UNDEF;
217  }
218 }
219 
231 static inline uint8_t gnrc_nettype_to_protnum(gnrc_nettype_t type)
232 {
233  switch (type) {
234 #ifdef MODULE_GNRC_ICMPV6
235  case GNRC_NETTYPE_ICMPV6:
236  return PROTNUM_ICMPV6;
237 #endif
238 #ifdef MODULE_GNRC_IPV6
239  case GNRC_NETTYPE_IPV6:
240  return PROTNUM_IPV6;
241 #endif
242 #ifdef MODULE_GNRC_TCP
243  case GNRC_NETTYPE_TCP:
244  return PROTNUM_TCP;
245 #endif
246 #ifdef MODULE_GNRC_UDP
247  case GNRC_NETTYPE_UDP:
248  return PROTNUM_UDP;
249 #endif
250  default:
251  return PROTNUM_RESERVED;
252  }
253 }
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* NET_GNRC_NETTYPE_H */
260 
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:231
#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:159
#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:132
#define PROTNUM_IPV6_EXT_ESP
IPv6 Encap Security Payload Extension Header.
Definition: protnum.h:86
Protocol is UDP.
Definition: nettype.h:95
#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:118
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:186
Protocol is 6LoWPAN.
Definition: nettype.h:56
Protocol is IPv6.
Definition: nettype.h:75
#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:81
#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