Contiki-NG
Loading...
Searching...
No Matches
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 An address context for IPHC address compression
195 * each context can have upto 8 bytes
196 */
198 uint8_t used; /* possibly use as prefix-length */
199 uint8_t number;
200 uint8_t prefix[8];
201};
202
203/**
204 * \name Address compressibility test functions
205 * @{
206 */
207
208/**
209 * \brief check whether we can compress the IID in
210 * address 'a' to 16 bits.
211 * This is used for unicast addresses only, and is true
212 * if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX
213 * NOTE: we currently assume 64-bits prefixes
214 */
215#define sicslowpan_is_iid_16_bit_compressable(a) \
216 ((((a)->u16[4]) == 0) && \
217 (((a)->u8[10]) == 0)&& \
218 (((a)->u8[11]) == 0xff)&& \
219 (((a)->u8[12]) == 0xfe)&& \
220 (((a)->u8[13]) == 0))
221
222/**
223 * \brief check whether the 9-bit group-id of the
224 * compressed multicast address is known. It is true
225 * if the 9-bit group is the all nodes or all routers
226 * group.
227 * \param a is typed uint8_t *
228 */
229#define sicslowpan_is_mcast_addr_decompressable(a) \
230 (((*a & 0x01) == 0) && \
231 ((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))
232
233/**
234 * \brief check whether the 112-bit group-id of the
235 * multicast address is mappable to a 9-bit group-id
236 * It is true if the group is the all nodes or all
237 * routers group.
238*/
239#define sicslowpan_is_mcast_addr_compressable(a) \
240 ((((a)->u16[1]) == 0) && \
241 (((a)->u16[2]) == 0) && \
242 (((a)->u16[3]) == 0) && \
243 (((a)->u16[4]) == 0) && \
244 (((a)->u16[5]) == 0) && \
245 (((a)->u16[6]) == 0) && \
246 (((a)->u8[14]) == 0) && \
247 ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2)))
248
249/* FFXX::00XX:XXXX:XXXX */
250#define sicslowpan_is_mcast_addr_compressable48(a) \
251 ((((a)->u16[1]) == 0) && \
252 (((a)->u16[2]) == 0) && \
253 (((a)->u16[3]) == 0) && \
254 (((a)->u16[4]) == 0) && \
255 (((a)->u8[10]) == 0))
256
257/* FFXX::00XX:XXXX */
258#define sicslowpan_is_mcast_addr_compressable32(a) \
259 ((((a)->u16[1]) == 0) && \
260 (((a)->u16[2]) == 0) && \
261 (((a)->u16[3]) == 0) && \
262 (((a)->u16[4]) == 0) && \
263 (((a)->u16[5]) == 0) && \
264 (((a)->u8[12]) == 0))
265
266/* FF02::00XX */
267#define sicslowpan_is_mcast_addr_compressable8(a) \
268 ((((a)->u8[1]) == 2) && \
269 (((a)->u16[1]) == 0) && \
270 (((a)->u16[2]) == 0) && \
271 (((a)->u16[3]) == 0) && \
272 (((a)->u16[4]) == 0) && \
273 (((a)->u16[5]) == 0) && \
274 (((a)->u16[6]) == 0) && \
275 (((a)->u8[14]) == 0))
276
277/** @} */
278
279/**
280 * The structure of a next header compressor.
281 *
282 * TODO: needs more parameters when compressing extension headers, etc.
283 */
285 int (* is_compressable)(uint8_t next_header);
286
287 /** compress next header (TCP/UDP, etc) - ptr points to next header to
288 compress */
289 int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
290
291 /** uncompress next header (TCP/UDP, etc) - ptr points to next header to
292 uncompress */
293 int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
294
295};
296
297extern const struct network_driver sicslowpan_driver;
298
299#endif /* SICSLOWPAN_H_ */
300/** @} */
MAC driver header file.
The structure of a network driver in Contiki.
Definition netstack.h:115
An address context for IPHC address compression each context can have upto 8 bytes.
Definition sicslowpan.h:195
The structure of a next header compressor.
Definition sicslowpan.h:282
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:287
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:291
Header file for the uIP TCP/IP stack.