Contiki-NG
os
net
ipv6
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
/**
170
* \name LOWPAN_UDP encoding (works together with IPHC)
171
* @{
172
*/
173
#define SICSLOWPAN_NHC_UDP_MASK 0xF8
174
#define SICSLOWPAN_NHC_UDP_ID 0xF0
175
#define SICSLOWPAN_NHC_UDP_CHECKSUMC 0x04
176
#define SICSLOWPAN_NHC_UDP_CHECKSUMI 0x00
177
/* values for port compression, _with checksum_ ie bit 5 set to 0 */
178
#define SICSLOWPAN_NHC_UDP_CS_P_00 0xF0
/* all inline */
179
#define SICSLOWPAN_NHC_UDP_CS_P_01 0xF1
/* source 16bit inline, dest = 0xF0 + 8 bit inline */
180
#define SICSLOWPAN_NHC_UDP_CS_P_10 0xF2
/* source = 0xF0 + 8bit inline, dest = 16 bit inline */
181
#define SICSLOWPAN_NHC_UDP_CS_P_11 0xF3
/* source & dest = 0xF0B + 4bit inline */
182
/** @} */
183
184
185
/**
186
* \name The 6lowpan "headers" length
187
* @{
188
*/
189
190
#define SICSLOWPAN_IPV6_HDR_LEN 1
/*one byte*/
191
#define SICSLOWPAN_HC1_HDR_LEN 3
192
#define SICSLOWPAN_HC1_HC_UDP_HDR_LEN 7
193
#define SICSLOWPAN_FRAG1_HDR_LEN 4
194
#define SICSLOWPAN_FRAGN_HDR_LEN 5
195
/** @} */
196
197
/**
198
* \brief The header for fragments
199
* \note We do not define different structures for FRAG1
200
* and FRAGN headers, which are different. For FRAG1, the
201
* offset field is just not used
202
*/
203
/* struct sicslowpan_frag_hdr { */
204
/* uint16_t dispatch_size; */
205
/* uint16_t tag; */
206
/* uint8_t offset; */
207
/* }; */
208
209
/**
210
* \brief The HC1 header when HC_UDP is not used
211
*
212
* When all fields are compressed and HC_UDP is not used,
213
* we use this structure. If HC_UDP is used, the ttl is
214
* in another spot, and we use the sicslowpan_hc1_hc_udp
215
* structure
216
*/
217
/* struct sicslowpan_hc1_hdr { */
218
/* uint8_t dispatch; */
219
/* uint8_t encoding; */
220
/* uint8_t ttl; */
221
/* }; */
222
223
/**
224
* \brief HC1 followed by HC_UDP
225
*/
226
/* struct sicslowpan_hc1_hc_udp_hdr { */
227
/* uint8_t dispatch; */
228
/* uint8_t hc1_encoding; */
229
/* uint8_t hc_udp_encoding; */
230
/* uint8_t ttl; */
231
/* uint8_t ports; */
232
/* uint16_t udpchksum; */
233
/* }; */
234
235
/**
236
* \brief An address context for IPHC address compression
237
* each context can have upto 8 bytes
238
*/
239
struct
sicslowpan_addr_context
{
240
uint8_t used;
/* possibly use as prefix-length */
241
uint8_t number;
242
uint8_t prefix[8];
243
};
244
245
/**
246
* \name Address compressibility test functions
247
* @{
248
*/
249
250
/**
251
* \brief check whether we can compress the IID in
252
* address 'a' to 16 bits.
253
* This is used for unicast addresses only, and is true
254
* if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX
255
* NOTE: we currently assume 64-bits prefixes
256
*/
257
#define sicslowpan_is_iid_16_bit_compressable(a) \
258
((((a)->u16[4]) == 0) && \
259
(((a)->u8[10]) == 0)&& \
260
(((a)->u8[11]) == 0xff)&& \
261
(((a)->u8[12]) == 0xfe)&& \
262
(((a)->u8[13]) == 0))
263
264
/**
265
* \brief check whether the 9-bit group-id of the
266
* compressed multicast address is known. It is true
267
* if the 9-bit group is the all nodes or all routers
268
* group.
269
* \param a is typed uint8_t *
270
*/
271
#define sicslowpan_is_mcast_addr_decompressable(a) \
272
(((*a & 0x01) == 0) && \
273
((*(a + 1) == 0x01) || (*(a + 1) == 0x02)))
274
275
/**
276
* \brief check whether the 112-bit group-id of the
277
* multicast address is mappable to a 9-bit group-id
278
* It is true if the group is the all nodes or all
279
* routers group.
280
*/
281
#define sicslowpan_is_mcast_addr_compressable(a) \
282
((((a)->u16[1]) == 0) && \
283
(((a)->u16[2]) == 0) && \
284
(((a)->u16[3]) == 0) && \
285
(((a)->u16[4]) == 0) && \
286
(((a)->u16[5]) == 0) && \
287
(((a)->u16[6]) == 0) && \
288
(((a)->u8[14]) == 0) && \
289
((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2)))
290
291
/* FFXX::00XX:XXXX:XXXX */
292
#define sicslowpan_is_mcast_addr_compressable48(a) \
293
((((a)->u16[1]) == 0) && \
294
(((a)->u16[2]) == 0) && \
295
(((a)->u16[3]) == 0) && \
296
(((a)->u16[4]) == 0) && \
297
(((a)->u8[10]) == 0))
298
299
/* FFXX::00XX:XXXX */
300
#define sicslowpan_is_mcast_addr_compressable32(a) \
301
((((a)->u16[1]) == 0) && \
302
(((a)->u16[2]) == 0) && \
303
(((a)->u16[3]) == 0) && \
304
(((a)->u16[4]) == 0) && \
305
(((a)->u16[5]) == 0) && \
306
(((a)->u8[12]) == 0))
307
308
/* FF02::00XX */
309
#define sicslowpan_is_mcast_addr_compressable8(a) \
310
((((a)->u8[1]) == 2) && \
311
(((a)->u16[1]) == 0) && \
312
(((a)->u16[2]) == 0) && \
313
(((a)->u16[3]) == 0) && \
314
(((a)->u16[4]) == 0) && \
315
(((a)->u16[5]) == 0) && \
316
(((a)->u16[6]) == 0) && \
317
(((a)->u8[14]) == 0))
318
319
/** @} */
320
321
/**
322
* The structure of a next header compressor.
323
*
324
* TODO: needs more parameters when compressing extension headers, etc.
325
*/
326
struct
sicslowpan_nh_compressor
{
327
int (* is_compressable)(uint8_t next_header);
328
329
/** compress next header (TCP/UDP, etc) - ptr points to next header to
330
compress */
331
int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len);
332
333
/** uncompress next header (TCP/UDP, etc) - ptr points to next header to
334
uncompress */
335
int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len);
336
337
};
338
339
int
sicslowpan_get_last_rssi(
void
);
340
341
extern
const
struct
network_driver
sicslowpan_driver;
342
343
#endif
/* SICSLOWPAN_H_ */
344
/** @} */
sicslowpan_nh_compressor
The structure of a next header compressor.
Definition:
sicslowpan.h:326
network_driver
The structure of a network driver in Contiki.
Definition:
netstack.h:117
sicslowpan_addr_context
The header for fragments.
Definition:
sicslowpan.h:239
uip.h
Header file for the uIP TCP/IP stack.
mac.h
MAC driver header file
Generated on Sat May 30 2020 17:03:42 for Contiki-NG by
1.8.13