00001 /* 00002 * Copyright (c) 2010, FIP AUTHORS 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1) Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2) Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 00015 * 3) Neither the name of the FIP AUTHORS nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 /** 00032 * @addtogroup fip_nd6 00033 * @{ 00034 */ 00035 00036 /** 00037 * @file 00038 * Neighbour Discovery for IPv6 (RFC4861) 00039 * 00040 * @author 00041 * Colin O'Flynn 00042 */ 00043 00044 #ifndef FIP_ND6_H_ 00045 #define FIP_ND6_H_ 00046 00047 #include "fip_compiler.h" 00048 00049 /* ################################## TYPES ############################### */ 00050 00051 /** Router Solicitation Message Type */ 00052 _PACKSTART 00053 typedef struct 00054 { 00055 uint8_t type; /**< ICMPv6 Type (133) */ 00056 uint8_t code; /**< ICMPv6 Code (0) */ 00057 uint16_t checksum; /**< ICMPv6 Checksum */ 00058 uint32_t reserved; /**< Reserved field */ 00059 } _PS fip_nd6_rs_t; 00060 _PACKEND 00061 00062 /** Router Advertisement Message Type */ 00063 _PACKSTART 00064 typedef struct 00065 { 00066 uint8_t type; /**< ICMPv6 Type (134) */ 00067 uint8_t code; /**< ICMPv6 Code (0) */ 00068 uint16_t checksum; /**< ICMPv6 Checksum */ 00069 uint8_t curHopLimit; /**< RA Current Hop Limit */ 00070 uint8_t flagsReserved; /**< 2 flag bits + 6 reserved bits */ 00071 uint16_t routerLifetime; /**< Router lifetime in seconds */ 00072 uint32_t reachableTime; /**< Default reachable time in mS */ 00073 uint32_t retransTime; /**< Default retrans time in mS */ 00074 } _PS fip_nd6_ra_t; 00075 _PACKEND 00076 00077 /** Neighbour Solicitation Message Type */ 00078 _PACKSTART 00079 typedef struct 00080 { 00081 uint8_t type; /**< ICMPv6 Type (135) */ 00082 uint8_t code; /**< ICMPv6 Code (0) */ 00083 uint16_t checksum; /**< ICMPv6 Checksum */ 00084 uint32_t reserved; /**< Reserved field */ 00085 uint8_t targetAddress[16]; /**< Target IPv6 Address for this NS */ 00086 } _PS fip_nd6_ns_t; 00087 _PACKEND 00088 00089 /** Neighbour Advertisement Message Type */ 00090 _PACKSTART 00091 typedef struct 00092 { 00093 uint8_t type; /**< ICMPv6 Type (136) */ 00094 uint8_t code; /**< ICMPv6 Code (0) */ 00095 uint16_t checksum; /**< ICMPv6 Checksum */ 00096 uint8_t flags_reserved; /**< 3 flag bits, 5 reserved bits */ 00097 uint8_t reserved1; /**< Reserved */ 00098 uint8_t reserved2; /**< Reserved */ 00099 uint8_t reserved3; /**< Reserved */ 00100 uint8_t targetAddress[16]; /**< Target IPv6 Address for this NA */ 00101 } _PS fip_nd6_na_t; 00102 _PACKEND 00103 00104 /** Source/Target Link-Layer Option */ 00105 _PACKSTART 00106 typedef struct 00107 { 00108 uint8_t type; /**< Option Type: 1 = SLLAO, 2 = TLLAO */ 00109 uint8_t length; /**< Option length in 8 octet steps */ 00110 uint8_t linkLayerAddress[16]; /**< Variable length: link-layer address */ 00111 } _PS fip_nd6_llao_t; 00112 _PACKEND 00113 00114 /** Prefix Information Option */ 00115 _PACKSTART 00116 typedef struct 00117 { 00118 uint8_t type; /**< Option Type (3) */ 00119 uint8_t length; /**< Option length in 8 octet steps */ 00120 uint8_t prefixLength; /**< Length of prefix in bits */ 00121 uint8_t flags_reserved; /**< 2 bits flag, 6 bits reserved */ 00122 uint32_t validLifetime; /**< Prefix valid lifetime, in seconds */ 00123 uint32_t preferredLifetime; /**< Prefix preferred lifetime, in seconds */ 00124 uint32_t reserved2; /**< Reserved */ 00125 uint8_t prefixAddress[16]; /**< Prefix, unused bytes are zeroed */ 00126 } _PS fip_nd6_pio_t; 00127 _PACKEND 00128 00129 /** Redirected Header Option */ 00130 _PACKSTART 00131 typedef struct 00132 { 00133 uint8_t type; /**< Option Type (4) */ 00134 uint8_t length; /**< Option length in 8 octet steps */ 00135 uint16_t reserved1; /**< Reserved */ 00136 uint32_t reserved2; /**< Reserved */ 00137 uint8_t ipHeaderData[1280]; /**< As much as original message as possible */ 00138 } _PS fip_nd6_rho_t; 00139 _PACKEND 00140 00141 /** MTU Option */ 00142 _PACKSTART 00143 typedef struct 00144 { 00145 uint8_t type; /**< Option Type (5) */ 00146 uint8_t length; /**< Option length in 8 octet steps (1) */ 00147 uint16_t reserved1; /**< Reserved */ 00148 uint32_t mtu; /**< Value of MTU */ 00149 } _PS fip_nd6_mtuo_t; 00150 _PACKEND 00151 00152 /** Structure holding all the configuration for a specific interface */ 00153 typedef struct 00154 { 00155 uint32_t baseReachableTime; /**< RFC4851, Used to calculate the rachableTime every so often */ 00156 uint32_t reachableTime; /**< RFC4861, Time a node is considered reachable for */ 00157 uint32_t retransTime; /**< RFC4861, Time between NS transmissions in mS */ 00158 unsigned char MaxNeighbourAdvs; /**< RFC4861/RFC4862, how many unsolicited NA to send */ 00159 unsigned char DupAddrDetectTransmits; /**< RFC4861/RFC4862, How many duplicate address detection attempts */ 00160 uint32_t RtrSolicitationInterval32mS;/**< RFC4861, Base time to wait between router solicitations */ 00161 uint32_t NextRtrSolicitationTime32mS;/**< RFC4861, Time we send next router solicitation */ 00162 unsigned char RtrSolicitationsToSend; /**< RFC4861, How many router solicitations to send */ 00163 uint16_t RouterLifetimeAdv; /**< RFC4861, router lifetime we advertise */ 00164 uint32_t RtrAdvInterval32mS; /**< RFC4861, Base time to wait between router advertisements, 0 disables unsolicited RA */ 00165 uint32_t NextRtrAdvTime32ms; /**< RFC4861, Time we send next multicast router advertisement */ 00166 00167 uint32_t RtrSoliciationMaxTime32mS; /**< 6lowpan-nd extension */ 00168 fip_bool_t using6LPND; /**< 6lowpan-nd extensions enabled */ 00169 unsigned char SIXND_DefRouterIndex; /**< Index to entry in default router table we register with */ 00170 00171 } fip_nd6_if_t; 00172 00173 /** Address Registration Option */ 00174 _PACKSTART 00175 typedef struct 00176 { 00177 uint8_t type; /**< Type */ 00178 uint8_t length; /**< Option length is 2 */ 00179 uint8_t status; /**< Status for NA, set to 0 for NS */ 00180 uint8_t reserved; /**< Reserved */ 00181 uint16_t reserved2; /**< Reserved */ 00182 uint16_t lifetime; /**< Lifetime in 10-second granularity */ 00183 uint8_t eui64[8]; /**< EUI-64 of interface */ 00184 } _PS fip_nd6_aro_t; 00185 _PACKEND 00186 00187 /** 6LoWPAN Context Option */ 00188 _PACKSTART 00189 typedef struct 00190 { 00191 uint8_t type; /**< Type */ 00192 uint8_t length; /**< Option length = 2 or 3 */ 00193 uint8_t contextLength; /**< Context length in bits */ 00194 uint8_t contextIDFlags; /**< Context compression bit & ID */ 00195 uint16_t reserved; /**< Reserved */ 00196 uint16_t vlifetime; /**< Lifetime in 10-second granularity */ 00197 uint8_t context[16]; /**< Context padded to 8 or 16 bytes */ 00198 } _PS fip_nd6_6co_t; 00199 _PACKEND 00200 00201 /** Authoritative Border Router Option */ 00202 _PACKSTART 00203 typedef struct 00204 { 00205 uint8_t type; /**< Type */ 00206 uint8_t length; /**< Length = 3 */ 00207 uint16_t versionNumber; /**< Version number */ 00208 uint32_t reserved; /**< Reserved */ 00209 uint8_t address[16]; /**< 6LBR Address */ 00210 } _PS fip_nd6_abro_t; 00211 _PACKEND 00212 00213 /* ################################## DEFINES ############################### */ 00214 00215 /** Neighbour Advertisement Header: Is Router Flag */ 00216 #define FIP_ND6_NA_ROUTERFLAG (0x80) 00217 /** Neighbour Advertisement Header: Is Solicited Flag */ 00218 #define FIP_ND6_NA_SOLICITEDFLAG (0x40) 00219 /** Neighbour Advertisement Header: Override Flag */ 00220 #define FIP_ND6_NA_OVERRIDEFLAG (0x20) 00221 00222 /** Router Advertisement Header: Managed Address Configuration Flag */ 00223 #define FIP_ND6_RA_MFLAG (0x80) 00224 /** Router Advertisement Header: Other Configuration Flag */ 00225 #define FIP_ND6_RA_OFLAG (0x40) 00226 00227 /** ND Option Type: SLLAO */ 00228 #define FIP_ND6_OPTION_SLLAO (1) 00229 /** ND Option Type: TLLAO */ 00230 #define FIP_ND6_OPTION_TLLAO (2) 00231 /** ND Option Type: PIO */ 00232 #define FIP_ND6_OPTION_PIO (3) 00233 /** ND Option Type: RHO */ 00234 #define FIP_ND6_OPTION_RHO (4) 00235 /** ND Option Type: MTUO */ 00236 #define FIP_ND6_OPTION_MTUO (5) 00237 00238 /** ND Option Type: ARO */ 00239 #define FIP_ND6_OPTION_ARO (31) 00240 /** ND Option Type: 6CO */ 00241 #define FIP_ND6_OPTION_6CO (32) 00242 /** ND Option Type: ABRO */ 00243 #define FIP_ND6_OPTION_ABRO (33) 00244 00245 /** ND Prefix Information Option: On-Link Flag */ 00246 #define FIP_ND6_OPTION_PIO_LFLAG (0x80) 00247 /** ND Prefix Information Option: Autoconf Flag */ 00248 #define FIP_ND6_OPTION_PIO_AFLAG (0x40) 00249 00250 /** Address Registration Option Status Field: Success */ 00251 #define FIP_ARO_SUCCESS (0) 00252 00253 /** Address Registration Option Status Field: Duplicate Address */ 00254 #define FIP_ARO_DUPLICATE (1) 00255 00256 /** Address Registration Option Status Field: Neighbor Cache Full */ 00257 #define FIP_ARO_NCFULL (2) 00258 00259 /** 6LoWPAN Context Option: Valid for Compression Field */ 00260 #define FIP_6CO_CFLAG (1<<4) 00261 00262 00263 /* From RFC4861 */ 00264 #define FIP_ICMPV6_TYPE_ND_RS (133) 00265 #define FIP_ICMPV6_TYPE_ND_RA (134) 00266 #define FIP_ICMPV6_TYPE_ND_NS (135) 00267 #define FIP_ICMPV6_TYPE_ND_NA (136) 00268 00269 /* 6lowpan-nd types */ 00270 #define FIP_ICMPV6_TYPE_ND_DAR (156) 00271 #define FIP_ICMPV6_TYPE_ND_DAC (157) 00272 00273 /* ################################## FUNCTIONS ############################### */ 00274 00275 /* Generate functions - in fip_nd6_generate.c */ 00276 void fip_nd6_generateNS(const fip_ip6addr_t * const targetAddress, 00277 unsigned char indexToMyUnicast, 00278 const fip_ip6addr_t * const destAddress, 00279 const uint8_t * optionData, const unsigned char optionLen, 00280 fip_bool_t addLLAO); 00281 void fip_nd6_generateNA(fip_bool_t solicited, unsigned char indexToMyUnicast, 00282 const uint8_t * optionData, const unsigned char optionLen, 00283 fip_bool_t addLLAO); 00284 void fip_nd6_generateRS(unsigned char indexToMyUnicast); 00285 void fip_nd6_generateRA(unsigned char indexToMyUnicast, fip_bool_t multicast); 00286 00287 /* Generic functions - in fip_nd6.c */ 00288 void fip_nd6_periodicUnicast(fip_ifnum_t ifnum, unsigned char indexToUnicast); 00289 void fip_nd6_periodicIf(fip_ifnum_t ifnum); 00290 void fip_nd6_neighbourCache_add(fip_ifnum_t ifnum, const unsigned char * const ipaddr, fip_llptraddr_t llptraddr, fip_bool_t isRouter); 00291 00292 00293 #endif //FIP_ND6_H_ 00294 00295 /** @} */