Contiki 2.6
|
00001 /** 00002 * \addtogroup sicslowpan 00003 * @{ 00004 */ 00005 00006 /* 00007 * Copyright (c) 2008, Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. Neither the name of the Institute nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * This file is part of the Contiki operating system. 00035 * 00036 * $Id: sicslowpan.h,v 1.13 2010/03/26 10:28:51 joxe Exp $ 00037 */ 00038 /** 00039 * \file 00040 * Header file for the 6lowpan implementation 00041 * (RFC4944 and draft-hui-6lowpan-hc-01) 00042 * \author Adam Dunkels <adam@sics.se> 00043 * \author Nicolas Tsiftes <nvt@sics.se> 00044 * \author Niclas Finne <nfi@sics.se> 00045 * \author Mathilde Durvy <mdurvy@cisco.com> 00046 * \author Julien Abeille <jabeille@cisco.com> 00047 */ 00048 00049 #ifndef __SICSLOWPAN_H__ 00050 #define __SICSLOWPAN_H__ 00051 #include "net/uip.h" 00052 #include "net/mac/mac.h" 00053 00054 /** 00055 * \name General sicslowpan defines 00056 * @{ 00057 */ 00058 /* Min and Max compressible UDP ports - HC06 */ 00059 #define SICSLOWPAN_UDP_4_BIT_PORT_MIN 0xF0B0 00060 #define SICSLOWPAN_UDP_4_BIT_PORT_MAX 0xF0BF /* F0B0 + 15 */ 00061 #define SICSLOWPAN_UDP_8_BIT_PORT_MIN 0xF000 00062 #define SICSLOWPAN_UDP_8_BIT_PORT_MAX 0xF0FF /* F000 + 255 */ 00063 00064 /** @} */ 00065 00066 /** 00067 * \name 6lowpan compressions 00068 * @{ 00069 */ 00070 #define SICSLOWPAN_COMPRESSION_IPV6 0 00071 #define SICSLOWPAN_COMPRESSION_HC1 1 00072 #define SICSLOWPAN_COMPRESSION_HC06 2 00073 /** @} */ 00074 00075 /** 00076 * \name 6lowpan dispatches 00077 * @{ 00078 */ 00079 #define SICSLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 = 65 */ 00080 #define SICSLOWPAN_DISPATCH_HC1 0x42 /* 01000010 = 66 */ 00081 #define SICSLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx = ... */ 00082 #define SICSLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx */ 00083 #define SICSLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx */ 00084 /** @} */ 00085 00086 /** \name HC1 encoding 00087 * @{ 00088 */ 00089 #define SICSLOWPAN_HC1_NH_UDP 0x02 00090 #define SICSLOWPAN_HC1_NH_TCP 0x06 00091 #define SICSLOWPAN_HC1_NH_ICMP6 0x04 00092 /** @} */ 00093 00094 /** \name HC_UDP encoding (works together with HC1) 00095 * @{ 00096 */ 00097 #define SICSLOWPAN_HC_UDP_ALL_C 0xE0 00098 /** @} */ 00099 00100 /** 00101 * \name IPHC encoding 00102 * @{ 00103 */ 00104 /* 00105 * Values of fields within the IPHC encoding first byte 00106 * (C stands for compressed and I for inline) 00107 */ 00108 #define SICSLOWPAN_IPHC_FL_C 0x10 00109 #define SICSLOWPAN_IPHC_TC_C 0x08 00110 #define SICSLOWPAN_IPHC_NH_C 0x04 00111 #define SICSLOWPAN_IPHC_TTL_1 0x01 00112 #define SICSLOWPAN_IPHC_TTL_64 0x02 00113 #define SICSLOWPAN_IPHC_TTL_255 0x03 00114 #define SICSLOWPAN_IPHC_TTL_I 0x00 00115 00116 00117 /* Values of fields within the IPHC encoding second byte */ 00118 #define SICSLOWPAN_IPHC_CID 0x80 00119 00120 #define SICSLOWPAN_IPHC_SAC 0x40 00121 #define SICSLOWPAN_IPHC_SAM_00 0x00 00122 #define SICSLOWPAN_IPHC_SAM_01 0x10 00123 #define SICSLOWPAN_IPHC_SAM_10 0x20 00124 #define SICSLOWPAN_IPHC_SAM_11 0x30 00125 00126 #define SICSLOWPAN_IPHC_SAM_BIT 4 00127 00128 #define SICSLOWPAN_IPHC_M 0x08 00129 #define SICSLOWPAN_IPHC_DAC 0x04 00130 #define SICSLOWPAN_IPHC_DAM_00 0x00 00131 #define SICSLOWPAN_IPHC_DAM_01 0x01 00132 #define SICSLOWPAN_IPHC_DAM_10 0x02 00133 #define SICSLOWPAN_IPHC_DAM_11 0x03 00134 00135 #define SICSLOWPAN_IPHC_DAM_BIT 0 00136 00137 /* Link local context number */ 00138 #define SICSLOWPAN_IPHC_ADDR_CONTEXT_LL 0 00139 /* 16-bit multicast addresses compression */ 00140 #define SICSLOWPAN_IPHC_MCAST_RANGE 0xA0 00141 /** @} */ 00142 00143 /* NHC_EXT_HDR */ 00144 #define SICSLOWPAN_NHC_MASK 0xF0 00145 #define SICSLOWPAN_NHC_EXT_HDR 0xE0 00146 00147 /** 00148 * \name LOWPAN_UDP encoding (works together with IPHC) 00149 * @{ 00150 */ 00151 /** 00152 * \name LOWPAN_UDP encoding (works together with IPHC) 00153 * @{ 00154 */ 00155 #define SICSLOWPAN_NHC_UDP_MASK 0xF8 00156 #define SICSLOWPAN_NHC_UDP_ID 0xF0 00157 #define SICSLOWPAN_NHC_UDP_CHECKSUMC 0x04 00158 #define SICSLOWPAN_NHC_UDP_CHECKSUMI 0x00 00159 /* values for port compression, _with checksum_ ie bit 5 set to 0 */ 00160 #define SICSLOWPAN_NHC_UDP_CS_P_00 0xF0 /* all inline */ 00161 #define SICSLOWPAN_NHC_UDP_CS_P_01 0xF1 /* source 16bit inline, dest = 0xF0 + 8 bit inline */ 00162 #define SICSLOWPAN_NHC_UDP_CS_P_10 0xF2 /* source = 0xF0 + 8bit inline, dest = 16 bit inline */ 00163 #define SICSLOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */ 00164 /** @} */ 00165 00166 00167 /** 00168 * \name The 6lowpan "headers" length 00169 * @{ 00170 */ 00171 00172 #define SICSLOWPAN_IPV6_HDR_LEN 1 /*one byte*/ 00173 #define SICSLOWPAN_HC1_HDR_LEN 3 00174 #define SICSLOWPAN_HC1_HC_UDP_HDR_LEN 7 00175 #define SICSLOWPAN_FRAG1_HDR_LEN 4 00176 #define SICSLOWPAN_FRAGN_HDR_LEN 5 00177 /** @} */ 00178 00179 /** 00180 * \brief The header for fragments 00181 * \note We do not define different structures for FRAG1 00182 * and FRAGN headers, which are different. For FRAG1, the 00183 * offset field is just not used 00184 */ 00185 /* struct sicslowpan_frag_hdr { */ 00186 /* uint16_t dispatch_size; */ 00187 /* uint16_t tag; */ 00188 /* uint8_t offset; */ 00189 /* }; */ 00190 00191 /** 00192 * \brief The HC1 header when HC_UDP is not used 00193 * 00194 * When all fields are compressed and HC_UDP is not used, 00195 * we use this structure. If HC_UDP is used, the ttl is 00196 * in another spot, and we use the sicslowpan_hc1_hc_udp 00197 * structure 00198 */ 00199 /* struct sicslowpan_hc1_hdr { */ 00200 /* uint8_t dispatch; */ 00201 /* uint8_t encoding; */ 00202 /* uint8_t ttl; */ 00203 /* }; */ 00204 00205 /** 00206 * \brief HC1 followed by HC_UDP 00207 */ 00208 /* struct sicslowpan_hc1_hc_udp_hdr { */ 00209 /* uint8_t dispatch; */ 00210 /* uint8_t hc1_encoding; */ 00211 /* uint8_t hc_udp_encoding; */ 00212 /* uint8_t ttl; */ 00213 /* uint8_t ports; */ 00214 /* uint16_t udpchksum; */ 00215 /* }; */ 00216 00217 /** 00218 * \brief An address context for IPHC address compression 00219 * each context can have upto 8 bytes 00220 */ 00221 struct sicslowpan_addr_context { 00222 uint8_t used; /* possibly use as prefix-length */ 00223 uint8_t number; 00224 uint8_t prefix[8]; 00225 }; 00226 00227 /** 00228 * \name Address compressibility test functions 00229 * @{ 00230 */ 00231 00232 /** 00233 * \brief check whether we can compress the IID in 00234 * address 'a' to 16 bits. 00235 * This is used for unicast addresses only, and is true 00236 * if the address is on the format <PREFIX>::0000:00ff:fe00:XXXX 00237 * NOTE: we currently assume 64-bits prefixes 00238 */ 00239 #define sicslowpan_is_iid_16_bit_compressable(a) \ 00240 ((((a)->u16[4]) == 0) && \ 00241 (((a)->u8[10]) == 0)&& \ 00242 (((a)->u8[11]) == 0xff)&& \ 00243 (((a)->u8[12]) == 0xfe)&& \ 00244 (((a)->u8[13]) == 0)) 00245 00246 /** 00247 * \brief check whether the 9-bit group-id of the 00248 * compressed multicast address is known. It is true 00249 * if the 9-bit group is the all nodes or all routers 00250 * group. 00251 * \param a is typed uint8_t * 00252 */ 00253 #define sicslowpan_is_mcast_addr_decompressable(a) \ 00254 (((*a & 0x01) == 0) && \ 00255 ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) 00256 00257 /** 00258 * \brief check whether the 112-bit group-id of the 00259 * multicast address is mappable to a 9-bit group-id 00260 * It is true if the group is the all nodes or all 00261 * routers group. 00262 */ 00263 #define sicslowpan_is_mcast_addr_compressable(a) \ 00264 ((((a)->u16[1]) == 0) && \ 00265 (((a)->u16[2]) == 0) && \ 00266 (((a)->u16[3]) == 0) && \ 00267 (((a)->u16[4]) == 0) && \ 00268 (((a)->u16[5]) == 0) && \ 00269 (((a)->u16[6]) == 0) && \ 00270 (((a)->u8[14]) == 0) && \ 00271 ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2))) 00272 00273 /* FFXX::00XX:XXXX:XXXX */ 00274 #define sicslowpan_is_mcast_addr_compressable48(a) \ 00275 ((((a)->u16[1]) == 0) && \ 00276 (((a)->u16[2]) == 0) && \ 00277 (((a)->u16[3]) == 0) && \ 00278 (((a)->u16[4]) == 0) && \ 00279 (((a)->u8[10]) == 0)) 00280 00281 /* FFXX::00XX:XXXX */ 00282 #define sicslowpan_is_mcast_addr_compressable32(a) \ 00283 ((((a)->u16[1]) == 0) && \ 00284 (((a)->u16[2]) == 0) && \ 00285 (((a)->u16[3]) == 0) && \ 00286 (((a)->u16[4]) == 0) && \ 00287 (((a)->u16[5]) == 0) && \ 00288 (((a)->u8[12]) == 0)) 00289 00290 /* FF02::00XX */ 00291 #define sicslowpan_is_mcast_addr_compressable8(a) \ 00292 ((((a)->u8[1]) == 2) && \ 00293 (((a)->u16[1]) == 0) && \ 00294 (((a)->u16[2]) == 0) && \ 00295 (((a)->u16[3]) == 0) && \ 00296 (((a)->u16[4]) == 0) && \ 00297 (((a)->u16[5]) == 0) && \ 00298 (((a)->u16[6]) == 0) && \ 00299 (((a)->u8[14]) == 0)) 00300 00301 /** @} */ 00302 00303 /** 00304 * The structure of a next header compressor. 00305 * 00306 * TODO: needs more parameters when compressing extension headers, etc. 00307 */ 00308 struct sicslowpan_nh_compressor { 00309 int (* is_compressable)(uint8_t next_header); 00310 00311 /** compress next header (TCP/UDP, etc) - ptr points to next header to 00312 compress */ 00313 int (* compress)(uint8_t *compressed, uint8_t *uncompressed_len); 00314 00315 /** uncompress next header (TCP/UDP, etc) - ptr points to next header to 00316 uncompress */ 00317 int (* uncompress)(uint8_t *compressed, uint8_t *lowpanbuf, uint8_t *uncompressed_len); 00318 00319 }; 00320 00321 00322 extern const struct network_driver sicslowpan_driver; 00323 00324 #endif /* __SICSLOWPAN_H__ */ 00325 /** @} */