Contiki-NG
sicslowpan.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \file
35 * Header file for the 6lowpan implementation
36 * (RFC4944 and draft-hui-6lowpan-hc-01)
37 * \author Adam Dunkels <adam@sics.se>
38 * \author Nicolas Tsiftes <nvt@sics.se>
39 * \author Niclas Finne <nfi@sics.se>
40 * \author Mathilde Durvy <mdurvy@cisco.com>
41 * \author Julien Abeille <jabeille@cisco.com>
42 */
43
44/**
45 * \addtogroup sicslowpan
46 * @{
47 */
48
49#ifndef SICSLOWPAN_H_
50#define SICSLOWPAN_H_
51
52#include "net/ipv6/uip.h"
53#include "net/mac/mac.h"
54
55/**
56 * \name General sicslowpan defines
57 * @{
58 */
59/* Min and Max compressible UDP ports - HC06 */
60#define SICSLOWPAN_UDP_4_BIT_PORT_MIN 0xF0B0
61#define SICSLOWPAN_UDP_4_BIT_PORT_MAX 0xF0BF /* F0B0 + 15 */
62#define SICSLOWPAN_UDP_8_BIT_PORT_MIN 0xF000
63#define SICSLOWPAN_UDP_8_BIT_PORT_MAX 0xF0FF /* F000 + 255 */
64
65/** @} */
66
67/**
68 * \name 6lowpan compressions
69 * \note These are assumed to be in order - so that no compression is 0, then more and more
70 * compressed version follow. E.g. they can be used for comparing: if x > COMPRESSION_IPV6 ...
71 * @{
72 */
73#define SICSLOWPAN_COMPRESSION_IPV6 0 /* No compression */
74#define SICSLOWPAN_COMPRESSION_IPHC 1 /* RFC 6282 */
75#define SICSLOWPAN_COMPRESSION_6LORH 2 /* RFC 8025 for paging dispatch,
76 * draft-ietf-6lo-routin-dispatch-05 for 6LoRH. 6LoRH is not
77 * implemented yet -- only support for paging dispatch. */
78/** @} */
79
80/**
81 * \name 6lowpan dispatches
82 * @{
83 */
84#define SICSLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 = 65 */
85#define SICSLOWPAN_DISPATCH_HC1 0x42 /* 01000010 = 66 */
86#define SICSLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx = ... */
87#define SICSLOWPAN_DISPATCH_IPHC_MASK 0xe0
88#define SICSLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */
89#define SICSLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */
90#define SICSLOWPAN_DISPATCH_FRAG_MASK 0xf8
91#define SICSLOWPAN_DISPATCH_PAGING 0xf0 /* 1111xxxx */
92#define SICSLOWPAN_DISPATCH_PAGING_MASK 0xf0
93/** @} */
94
95/** \name HC1 encoding
96 * @{
97 */
98#define SICSLOWPAN_HC1_NH_UDP 0x02
99#define SICSLOWPAN_HC1_NH_TCP 0x06
100#define SICSLOWPAN_HC1_NH_ICMP6 0x04
101/** @} */
102
103/** \name HC_UDP encoding (works together with HC1)
104 * @{
105 */
106#define SICSLOWPAN_HC_UDP_ALL_C 0xE0
107/** @} */
108
109/**
110 * \name IPHC encoding
111 * @{
112 */
113/*
114 * Values of fields within the IPHC encoding first byte
115 * (C stands for compressed and I for inline)
116 */
117#define SICSLOWPAN_IPHC_FL_C 0x10
118#define SICSLOWPAN_IPHC_TC_C 0x08
119#define SICSLOWPAN_IPHC_NH_C 0x04
120#define SICSLOWPAN_IPHC_TTL_1 0x01
121#define SICSLOWPAN_IPHC_TTL_64 0x02
122#define SICSLOWPAN_IPHC_TTL_255 0x03
123#define SICSLOWPAN_IPHC_TTL_I 0x00
124
125
126/* Values of fields within the IPHC encoding second byte */
127#define SICSLOWPAN_IPHC_CID 0x80
128
129#define SICSLOWPAN_IPHC_SAC 0x40
130#define SICSLOWPAN_IPHC_SAM_00 0x00
131#define SICSLOWPAN_IPHC_SAM_01 0x10
132#define SICSLOWPAN_IPHC_SAM_10 0x20
133#define SICSLOWPAN_IPHC_SAM_11 0x30
134
135#define SICSLOWPAN_IPHC_SAM_BIT 4
136
137#define SICSLOWPAN_IPHC_M 0x08
138#define SICSLOWPAN_IPHC_DAC 0x04
139#define SICSLOWPAN_IPHC_DAM_00 0x00
140#define SICSLOWPAN_IPHC_DAM_01 0x01
141#define SICSLOWPAN_IPHC_DAM_10 0x02
142#define SICSLOWPAN_IPHC_DAM_11 0x03
143
144#define SICSLOWPAN_IPHC_DAM_BIT 0
145
146/* Link local context number */
147#define SICSLOWPAN_IPHC_ADDR_CONTEXT_LL 0
148/* 16-bit multicast addresses compression */
149#define SICSLOWPAN_IPHC_MCAST_RANGE 0xA0
150/** @} */
151
152/* NHC_EXT_HDR */
153#define SICSLOWPAN_NHC_MASK 0xF0
154#define SICSLOWPAN_NHC_EXT_HDR 0xE0
155#define SICSLOWPAN_NHC_BIT 0x01
156
157/* The header values */
158#define SICSLOWPAN_NHC_ETX_HDR_HBHO 0x00
159#define SICSLOWPAN_NHC_ETX_HDR_ROUTING 0x01
160#define SICSLOWPAN_NHC_ETX_HDR_FRAG 0x02
161#define SICSLOWPAN_NHC_ETX_HDR_DESTO 0x03
162#define SICSLOWPAN_NHC_ETX_HDR_MOH 0x04
163#define SICSLOWPAN_NHC_ETX_HDR_IPV6 0x07
164
165/**
166 * \name LOWPAN_UDP encoding (works together with IPHC)
167 * @{
168 */
169#define SICSLOWPAN_NHC_UDP_MASK 0xF8
170#define SICSLOWPAN_NHC_UDP_ID 0xF0
171#define SICSLOWPAN_NHC_UDP_CHECKSUMC 0x04
172#define SICSLOWPAN_NHC_UDP_CHECKSUMI 0x00
173/* values for port compression, _with checksum_ ie bit 5 set to 0 */
174#define SICSLOWPAN_NHC_UDP_CS_P_00 0xF0 /* all inline */
175#define SICSLOWPAN_NHC_UDP_CS_P_01 0xF1 /* source 16bit inline, dest = 0xF0 + 8 bit inline */
176#define SICSLOWPAN_NHC_UDP_CS_P_10 0xF2 /* source = 0xF0 + 8bit inline, dest = 16 bit inline */
177#define SICSLOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */
178/** @} */
179
180
181/**
182 * \name The 6lowpan "headers" length
183 * @{
184 */
185
186#define SICSLOWPAN_IPV6_HDR_LEN 1 /*one byte*/
187#define SICSLOWPAN_HC1_HDR_LEN 3
188#define SICSLOWPAN_HC1_HC_UDP_HDR_LEN 7
189#define SICSLOWPAN_FRAG1_HDR_LEN 4
190#define SICSLOWPAN_FRAGN_HDR_LEN 5
191/** @} */
192
193/**
194 * \brief The header for fragments
195 * \note We do not define different structures for FRAG1
196 * and FRAGN headers, which are different. For FRAG1, the
197 * offset field is just not used
198 */
199/* struct sicslowpan_frag_hdr { */
200/* uint16_t dispatch_size; */
201/* uint16_t tag; */
202/* uint8_t offset; */
203/* }; */
204
205/**
206 * \brief The HC1 header when HC_UDP is not used
207 *
208 * When all fields are compressed and HC_UDP is not used,
209 * we use this structure. If HC_UDP is used, the ttl is
210 * in another spot, and we use the sicslowpan_hc1_hc_udp
211 * structure
212 */
213/* struct sicslowpan_hc1_hdr { */
214/* uint8_t dispatch; */
215/* uint8_t encoding; */
216/* uint8_t ttl; */
217/* }; */
218
219/**
220 * \brief HC1 followed by HC_UDP
221 */
222/* struct sicslowpan_hc1_hc_udp_hdr { */
223/* uint8_t dispatch; */
224/* uint8_t hc1_encoding; */
225/* uint8_t hc_udp_encoding; */
226/* uint8_t ttl; */
227/* uint8_t ports; */
228/* uint16_t udpchksum; */
229/* }; */
230
231/**
232 * \brief An address context for IPHC address compression
233 * each context can have upto 8 bytes
234 */
236 uint8_t used; /* possibly use as prefix-length */
237 uint8_t number;
238 uint8_t prefix[8];
239};
240
241/**
242 * \name Address compressibility test functions
243 * @{
244 */
245
246/**
247 * \brief check whether we can compress the IID in
248 * address 'a' to 16 bits.
249 * This is used for unicast addresses only, and is true
250 * if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX
251 * NOTE: we currently assume 64-bits prefixes
252 */
253#define sicslowpan_is_iid_16_bit_compressable(a) \
254 ((((a)->u16[4]) == 0) && \
255 (((a)->u8[10]) == 0)&& \
256 (((a)->u8[11]) == 0xff)&& \
257 (((a)->u8[12]) == 0xfe)&& \
258 (((a)->u8[13]) == 0))
259
260/**
261 * \brief check whether the 9-bit group-id of the
262 * compressed multicast address is known. It is true
263 * if the 9-bit group is the all nodes or all routers
264 * group.
265 * \param a is typed uint8_t *
266 */
267#define sicslowpan_is_mcast_addr_decompressable(a) \
268 (((*a & 0x01) == 0) && \
269 ((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))
270
271/**
272 * \brief check whether the 112-bit group-id of the
273 * multicast address is mappable to a 9-bit group-id
274 * It is true if the group is the all nodes or all
275 * routers group.
276*/
277#define sicslowpan_is_mcast_addr_compressable(a) \
278 ((((a)->u16[1]) == 0) && \
279 (((a)->u16[2]) == 0) && \
280 (((a)->u16[3]) == 0) && \
281 (((a)->u16[4]) == 0) && \
282 (((a)->u16[5]) == 0) && \
283 (((a)->u16[6]) == 0) && \
284 (((a)->u8[14]) == 0) && \
285 ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2)))
286
287/* FFXX::00XX:XXXX:XXXX */
288#define sicslowpan_is_mcast_addr_compressable48(a) \
289 ((((a)->u16[1]) == 0) && \
290 (((a)->u16[2]) == 0) && \
291 (((a)->u16[3]) == 0) && \
292 (((a)->u16[4]) == 0) && \
293 (((a)->u8[10]) == 0))
294
295/* FFXX::00XX:XXXX */
296#define sicslowpan_is_mcast_addr_compressable32(a) \
297 ((((a)->u16[1]) == 0) && \
298 (((a)->u16[2]) == 0) && \
299 (((a)->u16[3]) == 0) && \
300 (((a)->u16[4]) == 0) && \
301 (((a)->u16[5]) == 0) && \
302 (((a)->u8[12]) == 0))
303
304/* FF02::00XX */
305#define sicslowpan_is_mcast_addr_compressable8(a) \
306 ((((a)->u8[1]) == 2) && \
307 (((a)->u16[1]) == 0) && \
308 (((a)->u16[2]) == 0) && \
309 (((a)->u16[3]) == 0) && \
310 (((a)->u16[4]) == 0) && \
311 (((a)->u16[5]) == 0) && \
312 (((a)->u16[6]) == 0) && \
313 (((a)->u8[14]) == 0))
314
315/** @} */
316
317/**
318 * The structure of a next header compressor.
319 *
320 * TODO: needs more parameters when compressing extension headers, etc.
321 */
323 int (* is_compressable)(uint8_t next_header);
324
325 /** compress next header (TCP/UDP, etc) - ptr points to next header to
326 compress */
327 int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
328
329 /** uncompress next header (TCP/UDP, etc) - ptr points to next header to
330 uncompress */
331 int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
332
333};
334
335extern const struct network_driver sicslowpan_driver;
336
337#endif /* SICSLOWPAN_H_ */
338/** @} */
MAC driver header file.
The structure of a network driver in Contiki.
Definition: netstack.h:117
The header for fragments.
Definition: sicslowpan.h:233
The structure of a next header compressor.
Definition: sicslowpan.h:320
int(* compress)(uint8_t *compressed, uint8_t *uncompressed_len)
compress next header (TCP/UDP, etc) - ptr points to next header to compress
Definition: sicslowpan.h:325
int(* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len)
uncompress next header (TCP/UDP, etc) - ptr points to next header to uncompress
Definition: sicslowpan.h:329
Header file for the uIP TCP/IP stack.