Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dhcpv6_common.h Source File

dhcpv6_common.h

Go to the documentation of this file.
00001 /**
00002  * @file dhcpv6_common.h
00003  * @brief Functions common to DHCPv6 client, server and relay agent
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_COMMON_H
00030 #define _DHCPV6_COMMON_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "core/ethernet.h"
00035 #include "ipv6/ipv6.h"
00036 
00037 //UDP ports used by DHCPv6 clients and servers
00038 #define DHCPV6_CLIENT_PORT 546
00039 #define DHCPV6_SERVER_PORT 547
00040 
00041 //Maximum DHCPv6 message size
00042 #define DHCPV6_MAX_MSG_SIZE 1232
00043 //Maximum DUID size (128 octets not including the type code)
00044 #define DHCPV6_MAX_DUID_SIZE 130
00045 
00046 //Maximum hop count in a relay-forward message
00047 #define DHCPV6_HOP_COUNT_LIMIT 32
00048 //Highest server preference value
00049 #define DHCPV6_MAX_SERVER_PREFERENCE 255
00050 //Infinite lifetime representation
00051 #define DHCPV6_INFINITE_TIME 0xFFFFFFFF
00052 
00053 
00054 /**
00055  * @brief DUID types
00056  **/
00057 
00058 typedef enum
00059 {
00060    DHCPV6_DUID_LLT = 1,
00061    DHCPV6_DUID_EN  = 2,
00062    DHCPV6_DUID_LL  = 3
00063 } Dhcpv6DuidType;
00064 
00065 
00066 /**
00067  * @brief Hardware types
00068  **/
00069 
00070 typedef enum
00071 {
00072    DHCPV6_HARDWARE_TYPE_ETH   = 1,
00073    DHCPV6_HARDWARE_TYPE_EUI64 = 27
00074 } Dhcpv6HardwareType;
00075 
00076 
00077 /**
00078  * @brief DHCPv6 message types
00079  **/
00080 
00081 typedef enum
00082 {
00083    DHCPV6_MSG_TYPE_SOLICIT      = 1,
00084    DHCPV6_MSG_TYPE_ADVERTISE    = 2,
00085    DHCPV6_MSG_TYPE_REQUEST      = 3,
00086    DHCPV6_MSG_TYPE_CONFIRM      = 4,
00087    DHCPV6_MSG_TYPE_RENEW        = 5,
00088    DHCPV6_MSG_TYPE_REBIND       = 6,
00089    DHCPV6_MSG_TYPE_REPLY        = 7,
00090    DHCPV6_MSG_TYPE_RELEASE      = 8,
00091    DHCPV6_MSG_TYPE_DECLINE      = 9,
00092    DHCPV6_MSG_TYPE_RECONFIGURE  = 10,
00093    DHCPV6_MSG_TYPE_INFO_REQUEST = 11,
00094    DHCPV6_MSG_TYPE_RELAY_FORW   = 12,
00095    DHCPV6_MSG_TYPE_RELAY_REPL   = 13
00096 } Dhcpv6MessageType;
00097 
00098 
00099 /**
00100  * @brief DHCPv6 option codes
00101  **/
00102 
00103 typedef enum
00104 {
00105    DHCPV6_OPTION_CLIENTID      = 1,
00106    DHCPV6_OPTION_SERVERID      = 2,
00107    DHCPV6_OPTION_IA_NA         = 3,
00108    DHCPV6_OPTION_IA_TA         = 4,
00109    DHCPV6_OPTION_IAADDR        = 5,
00110    DHCPV6_OPTION_ORO           = 6,
00111    DHCPV6_OPTION_PREFERENCE    = 7,
00112    DHCPV6_OPTION_ELAPSED_TIME  = 8,
00113    DHCPV6_OPTION_RELAY_MSG     = 9,
00114    DHCPV6_OPTION_AUTH          = 11,
00115    DHCPV6_OPTION_UNICAST       = 12,
00116    DHCPV6_OPTION_STATUS_CODE   = 13,
00117    DHCPV6_OPTION_RAPID_COMMIT  = 14,
00118    DHCPV6_OPTION_USER_CLASS    = 15,
00119    DHCPV6_OPTION_VENDOR_CLASS  = 16,
00120    DHCPV6_OPTION_VENDOR_OPTS   = 17,
00121    DHCPV6_OPTION_INTERFACE_ID  = 18,
00122    DHCPV6_OPTION_RECONF_MSG    = 19,
00123    DHCPV6_OPTION_RECONF_ACCEPT = 20,
00124    DHCPV6_OPTION_DNS_SERVERS   = 23,
00125    DHCPV6_OPTION_DOMAIN_LIST   = 24,
00126    DHCPV6_OPTION_IA_PD         = 25,
00127    DHCPV6_OPTION_IAPREFIX      = 26,
00128    DHCPV6_OPTION_FQDN          = 39
00129 } Dhcpv6OptionCode;
00130 
00131 
00132 /**
00133  * @brief Status code
00134  **/
00135 
00136 typedef enum
00137 {
00138    DHCPV6_STATUS_SUCCESS            = 0,
00139    DHCPV6_STATUS_UNSPEC_FAILURE     = 1,
00140    DHCPV6_STATUS_NO_ADDRS_AVAILABLE = 2,
00141    DHCPV6_STATUS_NO_BINDING         = 3,
00142    DHCPV6_STATUS_NOT_ON_LINK        = 4,
00143    DHCPV6_STATUS_USE_MULTICAST      = 5
00144 } Dhcpv6StatusCode;
00145 
00146 
00147 //CodeWarrior or Win32 compiler?
00148 #if defined(__CWCC__) || defined(_WIN32)
00149    #pragma pack(push, 1)
00150 #endif
00151 
00152 
00153 /**
00154  * @brief DUID-LLT structure
00155  **/
00156 
00157 typedef __start_packed struct
00158 {
00159    uint16_t type;           //0-1
00160    uint16_t hardwareType;   //2-3
00161    uint32_t time;           //4-7
00162    MacAddr linkLayerAddr;   //8-13
00163 } __end_packed Dhcpv6DuidLlt;
00164 
00165 
00166 /**
00167  * @brief DUID-EN structure
00168  **/
00169 
00170 typedef __start_packed struct
00171 {
00172    uint16_t type;             //0-1
00173    uint32_t enterpriseNumber; //2-5
00174    uint8_t identifier[];      //6
00175 } __end_packed Dhcpv6DuidEn;
00176 
00177 
00178 /**
00179  * @brief DUID-LL structure
00180  **/
00181 
00182 typedef __start_packed struct
00183 {
00184    uint16_t type;         //0-1
00185    uint16_t hardwareType; //2-3
00186 #if (ETH_SUPPORT == ENABLED)
00187    MacAddr linkLayerAddr; //4-9
00188 #else
00189    Eui64 linkLayerAddr;   //4-11
00190 #endif
00191 } __end_packed Dhcpv6DuidLl;
00192 
00193 
00194 /**
00195  * @brief DHCPv6 message
00196  **/
00197 
00198 typedef __start_packed struct
00199 {
00200    uint8_t msgType;          //0
00201    uint8_t transactionId[3]; //1-3
00202    uint8_t options[];        //4
00203 } __end_packed Dhcpv6Message;
00204 
00205 
00206 /**
00207  * @brief DHCPv6 relay agent message
00208  **/
00209 
00210 typedef __start_packed struct
00211 {
00212    uint8_t msgType;      //0
00213    uint8_t hopCount;     //1
00214    Ipv6Addr linkAddress; //2-17
00215    Ipv6Addr peerAddress; //18-33
00216    uint8_t options[];    //34
00217 } __end_packed Dhcpv6RelayMessage;
00218 
00219 
00220 /**
00221  * @brief DHCPv6 option
00222  **/
00223 
00224 typedef __start_packed struct
00225 {
00226    uint16_t code;   //0-1
00227    uint16_t length; //2-3
00228    uint8_t value[]; //4
00229 } __end_packed Dhcpv6Option;
00230 
00231 
00232 /**
00233  * @brief Identity Association for Non-temporary Addresses option
00234  **/
00235 
00236 typedef __start_packed struct
00237 {
00238    uint32_t iaId;     //0-3
00239    uint32_t t1;       //4-7
00240    uint32_t t2;       //8-11
00241    uint8_t options[]; //12
00242 } __end_packed Dhcpv6IaNaOption;
00243 
00244 
00245 /**
00246  * @brief Identity Association for Temporary Addresses option
00247  **/
00248 
00249 typedef __start_packed struct
00250 {
00251    uint32_t iaId;     //0-3
00252    uint8_t options[]; //4
00253 } Dhcpv6IaTaOption;
00254 
00255 
00256 /**
00257  * @brief IA Address option
00258  **/
00259 
00260 typedef __start_packed struct
00261 {
00262    Ipv6Addr address;           //0-15
00263    uint32_t preferredLifetime; //16-19
00264    uint32_t validLifetime;     //20-23
00265    uint8_t options[];          //24
00266 } __end_packed Dhcpv6IaAddrOption;
00267 
00268 
00269 /**
00270  * @brief Option Request option
00271  **/
00272 
00273 typedef __start_packed struct
00274 {
00275    uint16_t requestedOption[1]; //0-1
00276 } __end_packed Dhcpv6OroOption;
00277 
00278 
00279 /**
00280  * @brief Preference option
00281  **/
00282 
00283 typedef __start_packed struct
00284 {
00285    uint8_t value; //0
00286 } __end_packed Dhcpv6PreferenceOption;
00287 
00288 
00289 /**
00290  * @brief Elapsed Time option
00291  **/
00292 
00293 typedef __start_packed struct
00294 {
00295    uint16_t value; //0-1
00296 } __end_packed Dhcpv6ElapsedTimeOption;
00297 
00298 
00299 /**
00300  * @brief Authentication option
00301  **/
00302 
00303 typedef __start_packed struct
00304 {
00305    uint8_t protocol;           //0
00306    uint8_t algorithm;          //1
00307    uint8_t rdm;                //2
00308    uint8_t replayDetection[8]; //3-10
00309    uint8_t authInfo[];         //11
00310 } __end_packed Dhcpv6AuthOption;
00311 
00312 
00313 /**
00314  * @brief Server Unicast option
00315  **/
00316 
00317 typedef __start_packed struct
00318 {
00319    Ipv6Addr serverAddr; //0-15
00320 } __end_packed Dhcpv6ServerUnicastOption;
00321 
00322 
00323 /**
00324  * @brief Status Code option
00325  **/
00326 
00327 typedef __start_packed struct
00328 {
00329    uint16_t statusCode;    //0-1
00330    char_t statusMessage[]; //2
00331 } __end_packed Dhcpv6StatusCodeOption;
00332 
00333 
00334 /**
00335  * @brief Reconfigure Message option
00336  **/
00337 
00338 typedef __start_packed struct
00339 {
00340    uint8_t msgType; //0
00341 } __end_packed Dhcpv6ReconfMessageOption;
00342 
00343 
00344 /**
00345  * @brief DNS Recursive Name Server option
00346  **/
00347 
00348 typedef __start_packed struct
00349 {
00350    Ipv6Addr address[1]; //0-15
00351 } __end_packed Dhcpv6DnsServersOption;
00352 
00353 
00354 /**
00355  * @brief Domain Search List option
00356  **/
00357 
00358 typedef __start_packed struct
00359 {
00360    uint8_t searchList[1]; //0
00361 } __end_packed Dhcpv6DomainListOption;
00362 
00363 
00364 /**
00365  * @brief Identity Association for Prefix Delegation Option
00366  **/
00367 
00368 typedef __start_packed struct
00369 {
00370    uint32_t iaId;     //0-3
00371    uint32_t t1;       //4-7
00372    uint32_t t2;       //8-11
00373    uint8_t options[]; //12
00374 } __end_packed Dhcpv6IaPdOption;
00375 
00376 
00377 /**
00378  * @brief IA_PD Prefix option
00379  **/
00380 
00381 typedef __start_packed struct
00382 {
00383    uint32_t preferredLifetime; //0-3
00384    uint32_t validLifetime;     //4-7
00385    uint8_t prefixLength;       //8
00386    Ipv6Addr prefix;            //9-24
00387    uint8_t options[];          //25
00388 } __end_packed Dhcpv6IaPrefixOption;
00389 
00390 
00391 /**
00392  * @brief Fully Qualified Domain Name option
00393  **/
00394 
00395 typedef __start_packed struct
00396 {
00397 #ifdef _CPU_BIG_ENDIAN
00398    uint8_t mbz : 5;      //0
00399    uint8_t n : 1;
00400    uint8_t o : 1;
00401    uint8_t s : 1;
00402 #else
00403    uint8_t s : 1;        //0
00404    uint8_t o : 1;
00405    uint8_t n : 1;
00406    uint8_t mbz : 5;
00407 #endif
00408    uint8_t domainName[]; //1
00409 } __end_packed Dhcpv6FqdnOption;
00410 
00411 
00412 //CodeWarrior or Win32 compiler?
00413 #if defined(__CWCC__) || defined(_WIN32)
00414    #pragma pack(pop)
00415 #endif
00416 
00417 
00418 //DHCPv6 related constants
00419 extern const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR;
00420 extern const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR;
00421 
00422 //DHCPv6 related functions
00423 Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
00424 
00425 Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLength,
00426    uint16_t optionCode, const void *optionValue, size_t optionLength);
00427 
00428 Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLength,
00429    uint16_t optionCode, const void *optionValue, size_t optionLength);
00430 
00431 Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
00432    size_t optionsLength, uint16_t optionCode);
00433 
00434 int32_t dhcpv6Rand(int32_t value);
00435 int32_t dhcpv6RandRange(int32_t min, int32_t max);
00436 
00437 #endif
00438