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 fip_ipnum_t defaultNsAddr; /**< Source address to send NS from */ 00168 00169 uint32_t RtrSoliciationMaxTime32mS; /**< 6lowpan-nd extension */ 00170 fip_bool_t using6LPND; /**< 6lowpan-nd extensions enabled */ 00171 unsigned char SIXND_DefRouterIndex; /**< Index to entry in default router table we register with */ 00172 00173 } fip_nd6_if_t; 00174 00175 /** Address Registration Option */ 00176 _PACKSTART 00177 typedef struct 00178 { 00179 uint8_t type; /**< Type */ 00180 uint8_t length; /**< Option length is 2 */ 00181 uint8_t status; /**< Status for NA, set to 0 for NS */ 00182 uint8_t reserved; /**< Reserved */ 00183 uint16_t reserved2; /**< Reserved */ 00184 uint16_t lifetime; /**< Lifetime in 10-second granularity */ 00185 uint8_t eui64[8]; /**< EUI-64 of interface */ 00186 } _PS fip_nd6_aro_t; 00187 _PACKEND 00188 00189 /** 6LoWPAN Context Option */ 00190 _PACKSTART 00191 typedef struct 00192 { 00193 uint8_t type; /**< Type */ 00194 uint8_t length; /**< Option length = 2 or 3 */ 00195 uint8_t contextLength; /**< Context length in bits */ 00196 uint8_t contextIDFlags; /**< Context compression bit & ID */ 00197 uint16_t reserved; /**< Reserved */ 00198 uint16_t vlifetime; /**< Lifetime in 10-second granularity */ 00199 uint8_t context[16]; /**< Context padded to 8 or 16 bytes */ 00200 } _PS fip_nd6_6co_t; 00201 _PACKEND 00202 00203 /** Authoritative Border Router Option */ 00204 _PACKSTART 00205 typedef struct 00206 { 00207 uint8_t type; /**< Type */ 00208 uint8_t length; /**< Length = 3 */ 00209 uint16_t versionNumber; /**< Version number */ 00210 uint32_t reserved; /**< Reserved */ 00211 uint8_t address[16]; /**< 6LBR Address */ 00212 } _PS fip_nd6_abro_t; 00213 _PACKEND 00214 00215 /* ################################## DEFINES ############################### */ 00216 00217 /** Neighbour Advertisement Header: Is Router Flag */ 00218 #define FIP_ND6_NA_ROUTERFLAG (0x80) 00219 /** Neighbour Advertisement Header: Is Solicited Flag */ 00220 #define FIP_ND6_NA_SOLICITEDFLAG (0x40) 00221 /** Neighbour Advertisement Header: Override Flag */ 00222 #define FIP_ND6_NA_OVERRIDEFLAG (0x20) 00223 00224 /** Router Advertisement Header: Managed Address Configuration Flag */ 00225 #define FIP_ND6_RA_MFLAG (0x80) 00226 /** Router Advertisement Header: Other Configuration Flag */ 00227 #define FIP_ND6_RA_OFLAG (0x40) 00228 00229 /** ND Option Type: SLLAO */ 00230 #define FIP_ND6_OPTION_SLLAO (1) 00231 /** ND Option Type: TLLAO */ 00232 #define FIP_ND6_OPTION_TLLAO (2) 00233 /** ND Option Type: PIO */ 00234 #define FIP_ND6_OPTION_PIO (3) 00235 /** ND Option Type: RHO */ 00236 #define FIP_ND6_OPTION_RHO (4) 00237 /** ND Option Type: MTUO */ 00238 #define FIP_ND6_OPTION_MTUO (5) 00239 00240 /** ND Option Type: ARO */ 00241 #define FIP_ND6_OPTION_ARO (31) 00242 /** ND Option Type: 6CO */ 00243 #define FIP_ND6_OPTION_6CO (32) 00244 /** ND Option Type: ABRO */ 00245 #define FIP_ND6_OPTION_ABRO (33) 00246 00247 /** ND Prefix Information Option: On-Link Flag */ 00248 #define FIP_ND6_OPTION_PIO_LFLAG (0x80) 00249 /** ND Prefix Information Option: Autoconf Flag */ 00250 #define FIP_ND6_OPTION_PIO_AFLAG (0x40) 00251 00252 /** Address Registration Option Status Field: Success */ 00253 #define FIP_ARO_SUCCESS (0) 00254 00255 /** Address Registration Option Status Field: Duplicate Address */ 00256 #define FIP_ARO_DUPLICATE (1) 00257 00258 /** Address Registration Option Status Field: Neighbor Cache Full */ 00259 #define FIP_ARO_NCFULL (2) 00260 00261 /** 6LoWPAN Context Option: Valid for Compression Field */ 00262 #define FIP_6CO_CFLAG (1<<4) 00263 00264 00265 /* This could be made variable later */ 00266 #define MAX_MULTICAST_SOLICIT (3) 00267 00268 /* From RFC4861 */ 00269 #define FIP_ICMPV6_TYPE_ND_RS (133) 00270 #define FIP_ICMPV6_TYPE_ND_RA (134) 00271 #define FIP_ICMPV6_TYPE_ND_NS (135) 00272 #define FIP_ICMPV6_TYPE_ND_NA (136) 00273 00274 /* 6lowpan-nd types */ 00275 #define FIP_ICMPV6_TYPE_ND_DAR (156) 00276 #define FIP_ICMPV6_TYPE_ND_DAC (157) 00277 00278 /* ################################## FUNCTIONS ############################### */ 00279 00280 /* Generate functions - in fip_nd6_generate.c */ 00281 void fip_nd6_generateNS(const fip_ip6addr_t * const targetAddress, 00282 unsigned char indexToMyUnicast, 00283 const fip_ip6addr_t * const destAddress, 00284 const uint8_t * optionData, const unsigned char optionLen, 00285 fip_bool_t addLLAO); 00286 void fip_nd6_generateNA(fip_bool_t solicited, unsigned char indexToMyUnicast, 00287 const uint8_t * optionData, const unsigned char optionLen, 00288 fip_bool_t addLLAO); 00289 void fip_nd6_generateRS(unsigned char indexToMyUnicast); 00290 void fip_nd6_generateRA(unsigned char indexToMyUnicast, fip_bool_t multicast); 00291 00292 /* Generic functions - in fip_nd6.c */ 00293 void fip_nd6_periodicUnicast(fip_ifnum_t ifnum, unsigned char indexToUnicast); 00294 void fip_nd6_periodicIf(fip_ifnum_t ifnum); 00295 void fip_nd6_neighbourCache_add(fip_ifnum_t ifnum, const unsigned char * const ipaddr, fip_llptraddr_t llptraddr, fip_bool_t isRouter); 00296 00297 00298 #endif //FIP_ND6_H_ 00299 00300 /** @} */