Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dhcpv6_client.h Source File

dhcpv6_client.h

Go to the documentation of this file.
00001 /**
00002  * @file dhcpv6_client.h
00003  * @brief DHCPv6 client (Dynamic Host Configuration Protocol for IPv6)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _DHCPV6_CLIENT_H
00030 #define _DHCPV6_CLIENT_H
00031 
00032 //Dependencies
00033 #include "dhcpv6/dhcpv6_common.h"
00034 #include "core/socket.h"
00035 
00036 //DHCPv6 client support
00037 #ifndef DHCPV6_CLIENT_SUPPORT
00038    #define DHCPV6_CLIENT_SUPPORT DISABLED
00039 #elif (DHCPV6_CLIENT_SUPPORT != ENABLED && DHCPV6_CLIENT_SUPPORT != DISABLED)
00040    #error DHCPV6_CLIENT_SUPPORT parameter is not valid
00041 #endif
00042 
00043 //DHCPv6 client tick interval
00044 #ifndef DHCPV6_CLIENT_TICK_INTERVAL
00045    #define DHCPV6_CLIENT_TICK_INTERVAL 200
00046 #elif (DHCPV6_CLIENT_TICK_INTERVAL < 10)
00047    #error DHCPV6_CLIENT_TICK_INTERVAL parameter is not valid
00048 #endif
00049 
00050 //Maximum number of IPv6 addresses in the client's IA
00051 #ifndef DHCPV6_CLIENT_ADDR_LIST_SIZE
00052    #define DHCPV6_CLIENT_ADDR_LIST_SIZE 2
00053 #elif (DHCPV6_CLIENT_ADDR_LIST_SIZE < 1)
00054    #error DHCPV6_CLIENT_ADDR_LIST_SIZE parameter is not valid
00055 #endif
00056 
00057 //Maximum size of the client's FQDN
00058 #ifndef DHCPV6_CLIENT_MAX_FQDN_SIZE
00059    #define DHCPV6_CLIENT_MAX_FQDN_SIZE 16
00060 #elif (DHCPV6_CLIENT_MAX_FQDN_SIZE < 1)
00061    #error DHCPV6_CLIENT_MAX_FQDN_SIZE parameter is not valid
00062 #endif
00063 
00064 //Max delay of first Solicit
00065 #ifndef DHCPV6_CLIENT_SOL_MAX_DELAY
00066    #define DHCPV6_CLIENT_SOL_MAX_DELAY 1000
00067 #elif (DHCPV6_CLIENT_SOL_MAX_DELAY < 100)
00068    #error DHCPV6_CLIENT_SOL_MAX_DELAY parameter is not valid
00069 #endif
00070 
00071 //Initial Solicit timeout
00072 #ifndef DHCPV6_CLIENT_SOL_TIMEOUT
00073    #define DHCPV6_CLIENT_SOL_TIMEOUT 1000
00074 #elif (DHCPV6_CLIENT_SOL_TIMEOUT < 100)
00075    #error DHCPV6_CLIENT_SOL_TIMEOUT parameter is not valid
00076 #endif
00077 
00078 //Max Solicit timeout value
00079 #ifndef DHCPV6_CLIENT_SOL_MAX_RT
00080    #define DHCPV6_CLIENT_SOL_MAX_RT 120000
00081 #elif (DHCPV6_CLIENT_SOL_MAX_RT < 100)
00082    #error DHCPV6_CLIENT_SOL_MAX_RT parameter is not valid
00083 #endif
00084 
00085 //Initial Request timeout
00086 #ifndef DHCPV6_CLIENT_REQ_TIMEOUT
00087    #define DHCPV6_CLIENT_REQ_TIMEOUT 1000
00088 #elif (DHCPV6_CLIENT_REQ_TIMEOUT < 100)
00089    #error DHCPV6_CLIENT_REQ_TIMEOUT parameter is not valid
00090 #endif
00091 
00092 //Max Request timeout value
00093 #ifndef DHCPV6_CLIENT_REQ_MAX_RT
00094    #define DHCPV6_CLIENT_REQ_MAX_RT 30000
00095 #elif (DHCPV6_CLIENT_REQ_MAX_RT < 100)
00096    #error DHCPV6_CLIENT_REQ_MAX_RT parameter is not valid
00097 #endif
00098 
00099 //Max Request retry attempts
00100 #ifndef DHCPV6_CLIENT_REQ_MAX_RC
00101    #define DHCPV6_CLIENT_REQ_MAX_RC 10
00102 #elif (DHCPV6_CLIENT_REQ_MAX_RC < 1)
00103    #error DHCPV6_CLIENT_REQ_MAX_RC parameter is not valid
00104 #endif
00105 
00106 //Max delay of first Confirm
00107 #ifndef DHCPV6_CLIENT_CNF_MAX_DELAY
00108    #define DHCPV6_CLIENT_CNF_MAX_DELAY 1000
00109 #elif (DHCPV6_CLIENT_CNF_MAX_DELAY < 100)
00110    #error DHCPV6_CLIENT_CNF_MAX_DELAY parameter is not valid
00111 #endif
00112 
00113 //Initial Confirm timeout
00114 #ifndef DHCPV6_CLIENT_CNF_TIMEOUT
00115    #define DHCPV6_CLIENT_CNF_TIMEOUT 1000
00116 #elif (DHCPV6_CLIENT_CNF_TIMEOUT < 100)
00117    #error DHCPV6_CLIENT_CNF_TIMEOUT parameter is not valid
00118 #endif
00119 
00120 //Max Confirm timeout
00121 #ifndef DHCPV6_CLIENT_CNF_MAX_RT
00122    #define DHCPV6_CLIENT_CNF_MAX_RT 4000
00123 #elif (DHCPV6_CLIENT_CNF_MAX_RT < 100)
00124    #error DHCPV6_CLIENT_CNF_MAX_RT parameter is not valid
00125 #endif
00126 
00127 //Max Confirm duration
00128 #ifndef DHCPV6_CLIENT_CNF_MAX_RD
00129    #define DHCPV6_CLIENT_CNF_MAX_RD 10000
00130 #elif (DHCPV6_CLIENT_CNF_MAX_RD < 100)
00131    #error DHCPV6_CLIENT_CNF_MAX_RD parameter is not valid
00132 #endif
00133 
00134 //Initial Renew timeout
00135 #ifndef DHCPV6_CLIENT_REN_TIMEOUT
00136    #define DHCPV6_CLIENT_REN_TIMEOUT 10000
00137 #elif (DHCPV6_CLIENT_REN_TIMEOUT < 100)
00138    #error DHCPV6_CLIENT_REN_TIMEOUT parameter is not valid
00139 #endif
00140 
00141 //Max Renew timeout value
00142 #ifndef DHCPV6_CLIENT_REN_MAX_RT
00143    #define DHCPV6_CLIENT_REN_MAX_RT 600000
00144 #elif (DHCPV6_CLIENT_REN_MAX_RT < 100)
00145    #error DHCPV6_CLIENT_REN_MAX_RT parameter is not valid
00146 #endif
00147 
00148 //Initial Rebind timeout
00149 #ifndef DHCPV6_CLIENT_REB_TIMEOUT
00150    #define DHCPV6_CLIENT_REB_TIMEOUT 10000
00151 #elif (DHCPV6_CLIENT_REB_TIMEOUT < 100)
00152    #error DHCPV6_CLIENT_REB_TIMEOUT parameter is not valid
00153 #endif
00154 
00155 //Max Rebind timeout value
00156 #ifndef DHCPV6_CLIENT_REB_MAX_RT
00157    #define DHCPV6_CLIENT_REB_MAX_RT 600000
00158 #elif (DHCPV6_CLIENT_REB_MAX_RT < 100)
00159    #error DHCPV6_CLIENT_REB_MAX_RT parameter is not valid
00160 #endif
00161 
00162 //Max delay of first Information-request
00163 #ifndef DHCPV6_CLIENT_INF_MAX_DELAY
00164    #define DHCPV6_CLIENT_INF_MAX_DELAY 1000
00165 #elif (DHCPV6_CLIENT_INF_MAX_DELAY < 100)
00166    #error DHCPV6_CLIENT_INF_MAX_DELAY parameter is not valid
00167 #endif
00168 
00169 //Initial Information-request timeout
00170 #ifndef DHCPV6_CLIENT_INF_TIMEOUT
00171    #define DHCPV6_CLIENT_INF_TIMEOUT 1000
00172 #elif (DHCPV6_CLIENT_INF_TIMEOUT < 100)
00173    #error DHCPV6_CLIENT_INF_TIMEOUT parameter is not valid
00174 #endif
00175 
00176 //Max Information-request timeout value
00177 #ifndef DHCPV6_CLIENT_INF_MAX_RT
00178    #define DHCPV6_CLIENT_INF_MAX_RT 120000
00179 #elif (DHCPV6_CLIENT_INF_MAX_RT < 1000)
00180    #error DHCPV6_CLIENT_INF_MAX_RT parameter is not valid
00181 #endif
00182 
00183 //Initial Release timeout
00184 #ifndef DHCPV6_CLIENT_REL_TIMEOUT
00185    #define DHCPV6_CLIENT_REL_TIMEOUT 1000
00186 #elif (DHCPV6_CLIENT_REL_TIMEOUT < 100)
00187    #error DHCPV6_CLIENT_REL_TIMEOUT parameter is not valid
00188 #endif
00189 
00190 //Max Release attempts
00191 #ifndef DHCPV6_CLIENT_REL_MAX_RC
00192    #define DHCPV6_CLIENT_REL_MAX_RC 5
00193 #elif (DHCPV6_CLIENT_REL_MAX_RC < 1)
00194    #error DHCPV6_CLIENT_REL_MAX_RC parameter is not valid
00195 #endif
00196 
00197 //Initial Decline timeout
00198 #ifndef DHCPV6_CLIENT_DEC_TIMEOUT
00199    #define DHCPV6_CLIENT_DEC_TIMEOUT 1000
00200 #elif (DHCPV6_CLIENT_DEC_TIMEOUT < 100)
00201    #error DHCPV6_CLIENT_DEC_TIMEOUT parameter is not valid
00202 #endif
00203 
00204 //Max Decline attempts
00205 #ifndef DHCPV6_CLIENT_DEC_MAX_RC
00206    #define DHCPV6_CLIENT_DEC_MAX_RC 5
00207 #elif (DHCPV6_CLIENT_DEC_MAX_RC < 1)
00208    #error DHCPV6_CLIENT_DEC_MAX_RC parameter is not valid
00209 #endif
00210 
00211 //Initial Reconfigure timeout
00212 #ifndef DHCPV6_CLIENT_REC_TIMEOUT
00213    #define DHCPV6_CLIENT_REC_TIMEOUT 2000
00214 #elif (DHCPV6_CLIENT_REC_TIMEOUT < 100)
00215    #error DHCPV6_CLIENT_REC_TIMEOUT parameter is not valid
00216 #endif
00217 
00218 //Max Reconfigure attempts
00219 #ifndef DHCPV6_CLIENT_REC_MAX_RC
00220    #define DHCPV6_CLIENT_REC_MAX_RC 8
00221 #elif (DHCPV6_CLIENT_REC_MAX_RC < 1)
00222    #error DHCPV6_CLIENT_REC_MAX_RC parameter is not valid
00223 #endif
00224 
00225 //Forward declaration of Dhcpv6ClientContext structure
00226 struct _Dhcpv6ClientContext;
00227 #define Dhcpv6ClientContext struct _Dhcpv6ClientContext
00228 
00229 
00230 /**
00231  * @brief DHCPv6 client FSM states
00232  **/
00233 
00234 typedef enum
00235 {
00236    DHCPV6_STATE_INIT         = 0,
00237    DHCPV6_STATE_SOLICIT      = 1,
00238    DHCPV6_STATE_REQUEST      = 2,
00239    DHCPV6_STATE_INIT_CONFIRM = 3,
00240    DHCPV6_STATE_CONFIRM      = 4,
00241    DHCPV6_STATE_DAD          = 5,
00242    DHCPV6_STATE_BOUND        = 6,
00243    DHCPV6_STATE_RENEW        = 7,
00244    DHCPV6_STATE_REBIND       = 8,
00245    DHCPV6_STATE_RELEASE      = 9,
00246    DHCPV6_STATE_DECLINE      = 10
00247 } Dhcpv6State;
00248 
00249 
00250 /**
00251  * @brief DHCPv6 configuration timeout callback
00252  **/
00253 
00254 typedef void (*Dhcpv6TimeoutCallback)(Dhcpv6ClientContext *context,
00255    NetInterface *interface);
00256 
00257 
00258 /**
00259  * @brief Link state change callback
00260  **/
00261 
00262 typedef void (*Dhcpv6LinkChangeCallback)(Dhcpv6ClientContext *context,
00263    NetInterface *interface, bool_t linkState);
00264 
00265 
00266 /**
00267  * @brief FSM state change callback
00268  **/
00269 
00270 typedef void (*Dhcpv6StateChangeCallback)(Dhcpv6ClientContext *context,
00271    NetInterface *interface, Dhcpv6State state);
00272 
00273 
00274 /**
00275  * @brief DHCPv6 client settings
00276  **/
00277 
00278 typedef struct
00279 {
00280    NetInterface *interface;                    ///<Network interface to configure
00281    bool_t rapidCommit;                         ///<Quick configuration using rapid commit
00282    bool_t manualDnsConfig;                     ///<Force manual DNS configuration
00283    systime_t timeout;                          ///<DHCPv6 configuration timeout
00284    Dhcpv6TimeoutCallback timeoutEvent;         ///<DHCPv6 configuration timeout event
00285    Dhcpv6LinkChangeCallback linkChangeEvent;   ///<Link state change event
00286    Dhcpv6StateChangeCallback stateChangeEvent; ///<FSM state change event
00287 } Dhcpv6ClientSettings;
00288 
00289 
00290 /**
00291  * @brief IA address entry
00292  **/
00293 
00294 typedef struct
00295 {
00296    Ipv6Addr addr;              ///<IPv6 address
00297    uint32_t validLifetime;     ///<Valid lifetime
00298    uint32_t preferredLifetime; ///<Preferred lifetime
00299 } Dhcpv6ClientAddrEntry;
00300 
00301 
00302 /**
00303  * @brief Client's IA (Identity Association)
00304  **/
00305 
00306 typedef struct
00307 {
00308    uint32_t t1;                                                  ///<T1 parameter
00309    uint32_t t2;                                                  ///<T2 parameter
00310    Dhcpv6ClientAddrEntry addrList[DHCPV6_CLIENT_ADDR_LIST_SIZE]; ///<Set of IPv6 addresses
00311 } Dhcpv6ClientIa;
00312 
00313 
00314 /**
00315  * @brief DHCPv6 client context
00316  **/
00317 
00318 struct _Dhcpv6ClientContext
00319 {
00320    Dhcpv6ClientSettings settings;                   ///<DHCPv6 client settings
00321    bool_t running;                                  ///<This flag tells whether the DHCP client is running or not
00322    Dhcpv6State state;                               ///<Current state of the FSM
00323    bool_t timeoutEventDone;                         ///<Timeout callback function has been called
00324    systime_t timestamp;                             ///<Timestamp to manage retransmissions
00325    systime_t timeout;                               ///<Timeout value
00326    uint_t retransmitCount;                          ///<Retransmission counter
00327    uint8_t clientId[DHCPV6_MAX_DUID_SIZE];          ///<Client DUID
00328    size_t clientIdLength;                           ///<Length of the client DUID
00329    uint8_t clientFqdn[DHCPV6_CLIENT_MAX_FQDN_SIZE]; ///<Client's fully qualified domain name
00330    size_t clientFqdnLength;                         ///<Length of the client's FQDN
00331    uint8_t serverId[DHCPV6_MAX_DUID_SIZE];          ///<Server DUID
00332    size_t serverIdLength;                           ///<Length of the server DUID
00333    int_t serverPreference;                          ///<Preference value for the server
00334    uint32_t transactionId;                          ///<Value to match requests with replies
00335    systime_t configStartTime;                       ///<Address acquisition or renewal process start time
00336    systime_t exchangeStartTime;                     ///<Time at which the client sent the first message
00337    systime_t leaseStartTime;                        ///<Lease start time
00338    Dhcpv6ClientIa ia;                               ///<Identity association
00339 };
00340 
00341 
00342 //Tick counter to handle periodic operations
00343 extern systime_t dhcpv6ClientTickCounter;
00344 
00345 //DHCPv6 client related functions
00346 void dhcpv6ClientGetDefaultSettings(Dhcpv6ClientSettings *settings);
00347 error_t dhcpv6ClientInit(Dhcpv6ClientContext *context, const Dhcpv6ClientSettings *settings);
00348 error_t dhcpv6ClientStart(Dhcpv6ClientContext *context);
00349 error_t dhcpv6ClientStop(Dhcpv6ClientContext *context);
00350 error_t dhcpv6ClientRelease(Dhcpv6ClientContext *context);
00351 Dhcpv6State dhcpv6ClientGetState(Dhcpv6ClientContext *context);
00352 
00353 void dhcpv6ClientTick(Dhcpv6ClientContext *context);
00354 void dhcpv6ClientLinkChangeEvent(Dhcpv6ClientContext *context);
00355 
00356 void dhcpv6ClientStateInit(Dhcpv6ClientContext *context);
00357 void dhcpv6ClientStateSolicit(Dhcpv6ClientContext *context);
00358 void dhcpv6ClientStateRequest(Dhcpv6ClientContext *context);
00359 void dhcpv6ClientStateInitConfirm(Dhcpv6ClientContext *context);
00360 void dhcpv6ClientStateConfirm(Dhcpv6ClientContext *context);
00361 void dhcpv6ClientStateDad(Dhcpv6ClientContext *context);
00362 void dhcpv6ClientStateBound(Dhcpv6ClientContext *context);
00363 void dhcpv6ClientStateRenew(Dhcpv6ClientContext *context);
00364 void dhcpv6ClientStateRebind(Dhcpv6ClientContext *context);
00365 void dhcpv6ClientStateRelease(Dhcpv6ClientContext *context);
00366 void dhcpv6ClientStateDecline(Dhcpv6ClientContext *context);
00367 
00368 error_t dhcpv6ClientSendMessage(Dhcpv6ClientContext *context,
00369    Dhcpv6MessageType type);
00370 
00371 void dhcpv6ClientProcessMessage(NetInterface *interface,
00372    const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
00373    const NetBuffer *buffer, size_t offset, void *params);
00374 
00375 void dhcpv6ClientParseAdvertise(Dhcpv6ClientContext *context,
00376    const Dhcpv6Message *message, size_t length);
00377 
00378 void dhcpv6ClientParseReply(Dhcpv6ClientContext *context,
00379    const Dhcpv6Message *message, size_t length);
00380 
00381 error_t dhcpv6ClientParseIaNaOption(Dhcpv6ClientContext *context,
00382    const Dhcpv6Option *option);
00383 
00384 error_t dhcpv6ClientParseIaAddrOption(Dhcpv6ClientContext *context,
00385    const Dhcpv6Option *option);
00386 
00387 void dhcpv6ClientAddAddr(Dhcpv6ClientContext *context, const Ipv6Addr *addr,
00388    uint32_t validLifetime, uint32_t preferredLifetime);
00389 
00390 void dhcpv6ClientRemoveAddr(Dhcpv6ClientContext *context, const Ipv6Addr *addr);
00391 
00392 void dhcpv6ClientFlushAddrList(Dhcpv6ClientContext *context);
00393 
00394 error_t dhcpv6ClientGenerateDuid(Dhcpv6ClientContext *context);
00395 error_t dhcpv6ClientGenerateFqdn(Dhcpv6ClientContext *context);
00396 error_t dhcpv6ClientGenerateLinkLocalAddr(Dhcpv6ClientContext *context);
00397 
00398 bool_t dhcpv6ClientCheckServerId(Dhcpv6ClientContext *context,
00399    Dhcpv6Option *serverIdOption);
00400 
00401 void dhcpv6ClientCheckTimeout(Dhcpv6ClientContext *context);
00402 
00403 uint16_t dhcpv6ClientComputeElapsedTime(Dhcpv6ClientContext *context);
00404 
00405 void dhcpv6ClientChangeState(Dhcpv6ClientContext *context,
00406    Dhcpv6State newState, systime_t delay);
00407 
00408 void dhcpv6ClientDumpConfig(Dhcpv6ClientContext *context);
00409 
00410 #endif
00411