Contiki 3.x
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/ip/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  * @{
70  */
71 #define SICSLOWPAN_COMPRESSION_IPV6 0
72 #define SICSLOWPAN_COMPRESSION_HC1 1
73 #define SICSLOWPAN_COMPRESSION_HC06 2
74 /** @} */
75 
76 /**
77  * \name 6lowpan dispatches
78  * @{
79  */
80 #define SICSLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 = 65 */
81 #define SICSLOWPAN_DISPATCH_HC1 0x42 /* 01000010 = 66 */
82 #define SICSLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx = ... */
83 #define SICSLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */
84 #define SICSLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */
85 /** @} */
86 
87 /** \name HC1 encoding
88  * @{
89  */
90 #define SICSLOWPAN_HC1_NH_UDP 0x02
91 #define SICSLOWPAN_HC1_NH_TCP 0x06
92 #define SICSLOWPAN_HC1_NH_ICMP6 0x04
93 /** @} */
94 
95 /** \name HC_UDP encoding (works together with HC1)
96  * @{
97  */
98 #define SICSLOWPAN_HC_UDP_ALL_C 0xE0
99 /** @} */
100 
101 /**
102  * \name IPHC encoding
103  * @{
104  */
105 /*
106  * Values of fields within the IPHC encoding first byte
107  * (C stands for compressed and I for inline)
108  */
109 #define SICSLOWPAN_IPHC_FL_C 0x10
110 #define SICSLOWPAN_IPHC_TC_C 0x08
111 #define SICSLOWPAN_IPHC_NH_C 0x04
112 #define SICSLOWPAN_IPHC_TTL_1 0x01
113 #define SICSLOWPAN_IPHC_TTL_64 0x02
114 #define SICSLOWPAN_IPHC_TTL_255 0x03
115 #define SICSLOWPAN_IPHC_TTL_I 0x00
116 
117 
118 /* Values of fields within the IPHC encoding second byte */
119 #define SICSLOWPAN_IPHC_CID 0x80
120 
121 #define SICSLOWPAN_IPHC_SAC 0x40
122 #define SICSLOWPAN_IPHC_SAM_00 0x00
123 #define SICSLOWPAN_IPHC_SAM_01 0x10
124 #define SICSLOWPAN_IPHC_SAM_10 0x20
125 #define SICSLOWPAN_IPHC_SAM_11 0x30
126 
127 #define SICSLOWPAN_IPHC_SAM_BIT 4
128 
129 #define SICSLOWPAN_IPHC_M 0x08
130 #define SICSLOWPAN_IPHC_DAC 0x04
131 #define SICSLOWPAN_IPHC_DAM_00 0x00
132 #define SICSLOWPAN_IPHC_DAM_01 0x01
133 #define SICSLOWPAN_IPHC_DAM_10 0x02
134 #define SICSLOWPAN_IPHC_DAM_11 0x03
135 
136 #define SICSLOWPAN_IPHC_DAM_BIT 0
137 
138 /* Link local context number */
139 #define SICSLOWPAN_IPHC_ADDR_CONTEXT_LL 0
140 /* 16-bit multicast addresses compression */
141 #define SICSLOWPAN_IPHC_MCAST_RANGE 0xA0
142 /** @} */
143 
144 /* NHC_EXT_HDR */
145 #define SICSLOWPAN_NHC_MASK 0xF0
146 #define SICSLOWPAN_NHC_EXT_HDR 0xE0
147 
148 /**
149  * \name LOWPAN_UDP encoding (works together with IPHC)
150  * @{
151  */
152 /**
153  * \name LOWPAN_UDP encoding (works together with IPHC)
154  * @{
155  */
156 #define SICSLOWPAN_NHC_UDP_MASK 0xF8
157 #define SICSLOWPAN_NHC_UDP_ID 0xF0
158 #define SICSLOWPAN_NHC_UDP_CHECKSUMC 0x04
159 #define SICSLOWPAN_NHC_UDP_CHECKSUMI 0x00
160 /* values for port compression, _with checksum_ ie bit 5 set to 0 */
161 #define SICSLOWPAN_NHC_UDP_CS_P_00 0xF0 /* all inline */
162 #define SICSLOWPAN_NHC_UDP_CS_P_01 0xF1 /* source 16bit inline, dest = 0xF0 + 8 bit inline */
163 #define SICSLOWPAN_NHC_UDP_CS_P_10 0xF2 /* source = 0xF0 + 8bit inline, dest = 16 bit inline */
164 #define SICSLOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */
165 /** @} */
166 
167 
168 /**
169  * \name The 6lowpan "headers" length
170  * @{
171  */
172 
173 #define SICSLOWPAN_IPV6_HDR_LEN 1 /*one byte*/
174 #define SICSLOWPAN_HC1_HDR_LEN 3
175 #define SICSLOWPAN_HC1_HC_UDP_HDR_LEN 7
176 #define SICSLOWPAN_FRAG1_HDR_LEN 4
177 #define SICSLOWPAN_FRAGN_HDR_LEN 5
178 /** @} */
179 
180 /**
181  * \brief The header for fragments
182  * \note We do not define different structures for FRAG1
183  * and FRAGN headers, which are different. For FRAG1, the
184  * offset field is just not used
185  */
186 /* struct sicslowpan_frag_hdr { */
187 /* uint16_t dispatch_size; */
188 /* uint16_t tag; */
189 /* uint8_t offset; */
190 /* }; */
191 
192 /**
193  * \brief The HC1 header when HC_UDP is not used
194  *
195  * When all fields are compressed and HC_UDP is not used,
196  * we use this structure. If HC_UDP is used, the ttl is
197  * in another spot, and we use the sicslowpan_hc1_hc_udp
198  * structure
199  */
200 /* struct sicslowpan_hc1_hdr { */
201 /* uint8_t dispatch; */
202 /* uint8_t encoding; */
203 /* uint8_t ttl; */
204 /* }; */
205 
206 /**
207  * \brief HC1 followed by HC_UDP
208  */
209 /* struct sicslowpan_hc1_hc_udp_hdr { */
210 /* uint8_t dispatch; */
211 /* uint8_t hc1_encoding; */
212 /* uint8_t hc_udp_encoding; */
213 /* uint8_t ttl; */
214 /* uint8_t ports; */
215 /* uint16_t udpchksum; */
216 /* }; */
217 
218 /**
219  * \brief An address context for IPHC address compression
220  * each context can have upto 8 bytes
221  */
223  uint8_t used; /* possibly use as prefix-length */
224  uint8_t number;
225  uint8_t prefix[8];
226 };
227 
228 /**
229  * \name Address compressibility test functions
230  * @{
231  */
232 
233 /**
234  * \brief check whether we can compress the IID in
235  * address 'a' to 16 bits.
236  * This is used for unicast addresses only, and is true
237  * if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX
238  * NOTE: we currently assume 64-bits prefixes
239  */
240 #define sicslowpan_is_iid_16_bit_compressable(a) \
241  ((((a)->u16[4]) == 0) && \
242  (((a)->u8[10]) == 0)&& \
243  (((a)->u8[11]) == 0xff)&& \
244  (((a)->u8[12]) == 0xfe)&& \
245  (((a)->u8[13]) == 0))
246 
247 /**
248  * \brief check whether the 9-bit group-id of the
249  * compressed multicast address is known. It is true
250  * if the 9-bit group is the all nodes or all routers
251  * group.
252  * \param a is typed uint8_t *
253  */
254 #define sicslowpan_is_mcast_addr_decompressable(a) \
255  (((*a & 0x01) == 0) && \
256  ((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))
257 
258 /**
259  * \brief check whether the 112-bit group-id of the
260  * multicast address is mappable to a 9-bit group-id
261  * It is true if the group is the all nodes or all
262  * routers group.
263 */
264 #define sicslowpan_is_mcast_addr_compressable(a) \
265  ((((a)->u16[1]) == 0) && \
266  (((a)->u16[2]) == 0) && \
267  (((a)->u16[3]) == 0) && \
268  (((a)->u16[4]) == 0) && \
269  (((a)->u16[5]) == 0) && \
270  (((a)->u16[6]) == 0) && \
271  (((a)->u8[14]) == 0) && \
272  ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2)))
273 
274 /* FFXX::00XX:XXXX:XXXX */
275 #define sicslowpan_is_mcast_addr_compressable48(a) \
276  ((((a)->u16[1]) == 0) && \
277  (((a)->u16[2]) == 0) && \
278  (((a)->u16[3]) == 0) && \
279  (((a)->u16[4]) == 0) && \
280  (((a)->u8[10]) == 0))
281 
282 /* FFXX::00XX:XXXX */
283 #define sicslowpan_is_mcast_addr_compressable32(a) \
284  ((((a)->u16[1]) == 0) && \
285  (((a)->u16[2]) == 0) && \
286  (((a)->u16[3]) == 0) && \
287  (((a)->u16[4]) == 0) && \
288  (((a)->u16[5]) == 0) && \
289  (((a)->u8[12]) == 0))
290 
291 /* FF02::00XX */
292 #define sicslowpan_is_mcast_addr_compressable8(a) \
293  ((((a)->u8[1]) == 2) && \
294  (((a)->u16[1]) == 0) && \
295  (((a)->u16[2]) == 0) && \
296  (((a)->u16[3]) == 0) && \
297  (((a)->u16[4]) == 0) && \
298  (((a)->u16[5]) == 0) && \
299  (((a)->u16[6]) == 0) && \
300  (((a)->u8[14]) == 0))
301 
302 /** @} */
303 
304 /**
305  * The structure of a next header compressor.
306  *
307  * TODO: needs more parameters when compressing extension headers, etc.
308  */
310  int (* is_compressable)(uint8_t next_header);
311 
312  /** compress next header (TCP/UDP, etc) - ptr points to next header to
313  compress */
314  int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
315 
316  /** uncompress next header (TCP/UDP, etc) - ptr points to next header to
317  uncompress */
318  int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
319 
320 };
321 
322 int sicslowpan_get_last_rssi(void);
323 
324 extern const struct network_driver sicslowpan_driver;
325 
326 #endif /* SICSLOWPAN_H_ */
327 /** @} */
Header file for the uIP TCP/IP stack.
The header for fragments.
Definition: sicslowpan.h:222
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:314
The structure of a network driver in Contiki.
Definition: netstack.h:117
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:318
The structure of a next header compressor.
Definition: sicslowpan.h:309
MAC driver header file