Made MAC_CONF_CHANNEL_CHECK_RATE identical to CLOCK_CONF_SECOND in order to make...
[contiki-2.x.git] / core / net / sicslowpan.h
blob49488bcc209403d28a0322b8d7d5368dd9e628f4
1 /**
2 * \addtogroup sicslowpan
3 * @{
4 */
6 /*
7 * Copyright (c) 2008, Swedish Institute of Computer Science.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * This file is part of the Contiki operating system.
36 * $Id: sicslowpan.h,v 1.13 2010/03/26 10:28:51 joxe Exp $
38 /**
39 * \file
40 * Header file for the 6lowpan implementation
41 * (RFC4944 and draft-hui-6lowpan-hc-01)
42 * \author Adam Dunkels <adam@sics.se>
43 * \author Nicolas Tsiftes <nvt@sics.se>
44 * \author Niclas Finne <nfi@sics.se>
45 * \author Mathilde Durvy <mdurvy@cisco.com>
46 * \author Julien Abeille <jabeille@cisco.com>
49 #ifndef __SICSLOWPAN_H__
50 #define __SICSLOWPAN_H__
51 #include "net/uip.h"
52 #include "net/mac/mac.h"
54 /**
55 * \name General sicslowpan defines
56 * @{
58 /* Min and Max compressible UDP ports - HC06 */
59 #define SICSLOWPAN_UDP_4_BIT_PORT_MIN 0xF0B0
60 #define SICSLOWPAN_UDP_4_BIT_PORT_MAX 0xF0BF /* F0B0 + 15 */
61 #define SICSLOWPAN_UDP_8_BIT_PORT_MIN 0xF000
62 #define SICSLOWPAN_UDP_8_BIT_PORT_MAX 0xF0FF /* F000 + 255 */
64 /** @} */
66 /**
67 * \name 6lowpan compressions
68 * @{
70 #define SICSLOWPAN_COMPRESSION_IPV6 0
71 #define SICSLOWPAN_COMPRESSION_HC1 1
72 #define SICSLOWPAN_COMPRESSION_HC06 2
73 /** @} */
75 /**
76 * \name 6lowpan dispatches
77 * @{
79 #define SICSLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 = 65 */
80 #define SICSLOWPAN_DISPATCH_HC1 0x42 /* 01000010 = 66 */
81 #define SICSLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx = ... */
82 #define SICSLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */
83 #define SICSLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */
84 /** @} */
86 /** \name HC1 encoding
87 * @{
89 #define SICSLOWPAN_HC1_NH_UDP 0x02
90 #define SICSLOWPAN_HC1_NH_TCP 0x06
91 #define SICSLOWPAN_HC1_NH_ICMP6 0x04
92 /** @} */
94 /** \name HC_UDP encoding (works together with HC1)
95 * @{
97 #define SICSLOWPAN_HC_UDP_ALL_C 0xE0
98 /** @} */
101 * \name IPHC encoding
102 * @{
105 * Values of fields within the IPHC encoding first byte
106 * (C stands for compressed and I for inline)
108 #define SICSLOWPAN_IPHC_FL_C 0x10
109 #define SICSLOWPAN_IPHC_TC_C 0x08
110 #define SICSLOWPAN_IPHC_NH_C 0x04
111 #define SICSLOWPAN_IPHC_TTL_1 0x01
112 #define SICSLOWPAN_IPHC_TTL_64 0x02
113 #define SICSLOWPAN_IPHC_TTL_255 0x03
114 #define SICSLOWPAN_IPHC_TTL_I 0x00
117 /* Values of fields within the IPHC encoding second byte */
118 #define SICSLOWPAN_IPHC_CID 0x80
120 #define SICSLOWPAN_IPHC_SAC 0x40
121 #define SICSLOWPAN_IPHC_SAM_00 0x00
122 #define SICSLOWPAN_IPHC_SAM_01 0x10
123 #define SICSLOWPAN_IPHC_SAM_10 0x20
124 #define SICSLOWPAN_IPHC_SAM_11 0x30
126 #define SICSLOWPAN_IPHC_SAM_BIT 4
128 #define SICSLOWPAN_IPHC_M 0x08
129 #define SICSLOWPAN_IPHC_DAC 0x04
130 #define SICSLOWPAN_IPHC_DAM_00 0x00
131 #define SICSLOWPAN_IPHC_DAM_01 0x01
132 #define SICSLOWPAN_IPHC_DAM_10 0x02
133 #define SICSLOWPAN_IPHC_DAM_11 0x03
135 #define SICSLOWPAN_IPHC_DAM_BIT 0
137 /* Link local context number */
138 #define SICSLOWPAN_IPHC_ADDR_CONTEXT_LL 0
139 /* 16-bit multicast addresses compression */
140 #define SICSLOWPAN_IPHC_MCAST_RANGE 0xA0
141 /** @} */
143 /* NHC_EXT_HDR */
144 #define SICSLOWPAN_NHC_MASK 0xF0
145 #define SICSLOWPAN_NHC_EXT_HDR 0xE0
148 * \name LOWPAN_UDP encoding (works together with IPHC)
149 * @{
152 * \name LOWPAN_UDP encoding (works together with IPHC)
153 * @{
155 #define SICSLOWPAN_NHC_UDP_MASK 0xF8
156 #define SICSLOWPAN_NHC_UDP_ID 0xF0
157 #define SICSLOWPAN_NHC_UDP_CHECKSUMC 0x04
158 #define SICSLOWPAN_NHC_UDP_CHECKSUMI 0x00
159 /* values for port compression, _with checksum_ ie bit 5 set to 0 */
160 #define SICSLOWPAN_NHC_UDP_CS_P_00 0xF0 /* all inline */
161 #define SICSLOWPAN_NHC_UDP_CS_P_01 0xF1 /* source 16bit inline, dest = 0xF0 + 8 bit inline */
162 #define SICSLOWPAN_NHC_UDP_CS_P_10 0xF2 /* source = 0xF0 + 8bit inline, dest = 16 bit inline */
163 #define SICSLOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */
164 /** @} */
168 * \name The 6lowpan "headers" length
169 * @{
172 #define SICSLOWPAN_IPV6_HDR_LEN 1 /*one byte*/
173 #define SICSLOWPAN_HC1_HDR_LEN 3
174 #define SICSLOWPAN_HC1_HC_UDP_HDR_LEN 7
175 #define SICSLOWPAN_FRAG1_HDR_LEN 4
176 #define SICSLOWPAN_FRAGN_HDR_LEN 5
177 /** @} */
180 * \brief The header for fragments
181 * \note We do not define different structures for FRAG1
182 * and FRAGN headers, which are different. For FRAG1, the
183 * offset field is just not used
185 /* struct sicslowpan_frag_hdr { */
186 /* u16_t dispatch_size; */
187 /* u16_t tag; */
188 /* u8_t offset; */
189 /* }; */
192 * \brief The HC1 header when HC_UDP is not used
194 * When all fields are compressed and HC_UDP is not used,
195 * we use this structure. If HC_UDP is used, the ttl is
196 * in another spot, and we use the sicslowpan_hc1_hc_udp
197 * structure
199 /* struct sicslowpan_hc1_hdr { */
200 /* u8_t dispatch; */
201 /* u8_t encoding; */
202 /* u8_t ttl; */
203 /* }; */
206 * \brief HC1 followed by HC_UDP
208 /* struct sicslowpan_hc1_hc_udp_hdr { */
209 /* u8_t dispatch; */
210 /* u8_t hc1_encoding; */
211 /* u8_t hc_udp_encoding; */
212 /* u8_t ttl; */
213 /* u8_t ports; */
214 /* u16_t udpchksum; */
215 /* }; */
218 * \brief An address context for IPHC address compression
219 * each context can have upto 8 bytes
221 struct sicslowpan_addr_context {
222 u8_t used; /* possibly use as prefix-length */
223 u8_t number;
224 u8_t prefix[8];
228 * \name Address compressibility test functions
229 * @{
233 * \brief check whether we can compress the IID in
234 * address 'a' to 16 bits.
235 * This is used for unicast addresses only, and is true
236 * if first 49 bits of IID are 0
238 #define sicslowpan_is_iid_16_bit_compressable(a) \
239 ((((a)->u16[4]) == 0) && \
240 (((a)->u16[5]) == 0) && \
241 (((a)->u16[6]) == 0) && \
242 ((((a)->u8[14]) & 0x80) == 0))
245 * \brief check whether the 9-bit group-id of the
246 * compressed multicast address is known. It is true
247 * if the 9-bit group is the all nodes or all routers
248 * group.
249 * \param a is typed u8_t *
251 #define sicslowpan_is_mcast_addr_decompressable(a) \
252 (((*a & 0x01) == 0) && \
253 ((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))
256 * \brief check whether the 112-bit group-id of the
257 * multicast address is mappable to a 9-bit group-id
258 * It is true if the group is the all nodes or all
259 * routers group.
261 #define sicslowpan_is_mcast_addr_compressable(a) \
262 ((((a)->u16[1]) == 0) && \
263 (((a)->u16[2]) == 0) && \
264 (((a)->u16[3]) == 0) && \
265 (((a)->u16[4]) == 0) && \
266 (((a)->u16[5]) == 0) && \
267 (((a)->u16[6]) == 0) && \
268 (((a)->u8[14]) == 0) && \
269 ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2)))
271 /* FFXX::00XX:XXXX:XXXX */
272 #define sicslowpan_is_mcast_addr_compressable48(a) \
273 ((((a)->u16[1]) == 0) && \
274 (((a)->u16[2]) == 0) && \
275 (((a)->u16[3]) == 0) && \
276 (((a)->u16[4]) == 0) && \
277 (((a)->u8[10]) == 0))
279 /* FFXX::00XX:XXXX */
280 #define sicslowpan_is_mcast_addr_compressable32(a) \
281 ((((a)->u16[1]) == 0) && \
282 (((a)->u16[2]) == 0) && \
283 (((a)->u16[3]) == 0) && \
284 (((a)->u16[4]) == 0) && \
285 (((a)->u16[5]) == 0) && \
286 (((a)->u8[12]) == 0))
288 /* FF02::00XX */
289 #define sicslowpan_is_mcast_addr_compressable8(a) \
290 ((((a)->u8[1]) == 2) && \
291 (((a)->u16[1]) == 0) && \
292 (((a)->u16[2]) == 0) && \
293 (((a)->u16[3]) == 0) && \
294 (((a)->u16[4]) == 0) && \
295 (((a)->u16[5]) == 0) && \
296 (((a)->u16[6]) == 0) && \
297 (((a)->u8[14]) == 0))
299 /** @} */
302 * The structure of a next header compressor.
304 * TODO: needs more parameters when compressing extension headers, etc.
306 struct sicslowpan_nh_compressor {
307 int (* is_compressable)(uint8_t next_header);
309 /** compress next header (TCP/UDP, etc) - ptr points to next header to
310 compress */
311 int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
313 /** uncompress next header (TCP/UDP, etc) - ptr points to next header to
314 uncompress */
315 int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
320 extern const struct network_driver sicslowpan_driver;
322 extern const struct mac_driver *sicslowpan_mac;
323 #endif /* __SICSLOWPAN_H__ */
324 /** @} */