1 /* 2 * FreeRTOS+TCP V2.3.1 3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 * this software and associated documentation files (the "Software"), to deal in 7 * the Software without restriction, including without limitation the rights to 8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 * the Software, and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in all 13 * copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * http://aws.amazon.com/freertos 23 * http://www.FreeRTOS.org 24 */ 25 26 #ifndef FREERTOS_DHCPV6_H 27 #define FREERTOS_DHCPV6_H 28 29 /* Application level configuration options. */ 30 #include "FreeRTOS_DHCP.h" 31 #include "FreeRTOSIPConfig.h" 32 #include "IPTraceMacroDefaults.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* IPv6 option numbers. */ 39 /** @brief IPv6 DHCP option number - Solicit */ 40 #define DHCPv6_message_Type_Solicit 1U 41 /** @brief IPv6 DHCP option number - Advertise */ 42 #define DHCPv6_message_Type_Advertise 2U 43 /** @brief IPv6 DHCP option number - Request */ 44 #define DHCPv6_message_Type_Request 3U 45 /** @brief IPv6 DHCP option number - Confirm */ 46 #define DHCPv6_message_Type_Confirm 4U 47 /** @brief IPv6 DHCP option number - Renew */ 48 #define DHCPv6_message_Type_Renew 5U 49 /** @brief IPv6 DHCP option number - Reply */ 50 #define DHCPv6_message_Type_Reply 7U 51 /** @brief IPv6 DHCP option number - Release */ 52 #define DHCPv6_message_Type_Release 8U 53 /** @brief IPv6 DHCP option number - Decline */ 54 #define DHCPv6_message_Type_Decline 9U 55 56 /* Note: IA stands for "Identity_Association". */ 57 /** @brief IPv6 DHCP option - Client Identifier */ 58 #define DHCPv6_Option_Client_Identifier 1U 59 /** @brief IPv6 DHCP option - Server Identifier */ 60 #define DHCPv6_Option_Server_Identifier 2U 61 /** @brief IPv6 DHCP option - Non Temporary Address */ 62 #define DHCPv6_Option_NonTemporaryAddress 3U 63 /** @brief IPv6 DHCP option - Temporary Address */ 64 #define DHCPv6_Option_TemporaryAddress 4U 65 /** @brief IPv6 DHCP option - Identity_Association Address */ 66 #define DHCPv6_Option_IA_Address 5U 67 /** @brief IPv6 DHCP option - Option */ 68 #define DHCPv6_Option_Option_List 6U 69 /** @brief IPv6 DHCP option - Preference */ 70 #define DHCPv6_Option_Preference 7U 71 /** @brief IPv6 DHCP option - Elapsed time */ 72 #define DHCPv6_Option_Elapsed_Time 8U 73 /** @brief IPv6 DHCP option - Status code */ 74 #define DHCPv6_Option_Status_Code 13U 75 /** @brief IPv6 DHCP option - Recursive name server */ 76 #define DHCPv6_Option_DNS_recursive_name_server 23U 77 /** @brief IPv6 DHCP option - Search list */ 78 #define DHCPv6_Option_Domain_Search_List 24U 79 /** @brief IPv6 DHCP option - IA for prefix delegation */ 80 #define DHCPv6_Option_IA_for_Prefix_Delegation 25U 81 /** @brief IPv6 DHCP option - IA Prefix */ 82 #define DHCPv6_Option_IA_Prefix 26U 83 84 /** @brief DHCPv6 option request, used in combination with 'DHCPv6_Option_Option_List' */ 85 #define DHCP6_OPTION_REQUEST_DNS 0x0017 86 /** @brief DHCPv6 option request domain search list, used in combination with 'DHCPv6_Option_Option_List' */ 87 #define DHCP6_OPTION_REQUEST_DOMAIN_SEARCH_LIST 0x0018 88 89 #define DHCPv6_MAX_CLIENT_SERVER_ID_LENGTH 128 90 91 /** @brief The function time() counts since 1-1-1970. The DHCPv6 time-stamp however 92 * uses a time stamp that had zero on 1-1-2000. */ 93 #define SECS_FROM_1970_TILL_2000 946684800U 94 95 /** @brief If a lease time is not received, use the default of two days. 48 hours in ticks. 96 * Do not use the macro pdMS_TO_TICKS() here as integer overflow can occur. */ 97 #define dhcpv6DEFAULT_LEASE_TIME ( ( 48U * 60U * 60U ) * configTICK_RATE_HZ ) 98 99 /** @brief Don't allow the lease time to be too short. */ 100 #define dhcpv6MINIMUM_LEASE_TIME ( pdMS_TO_TICKS( 60000U ) ) /* 60 seconds in ticks. */ 101 102 /** @brief Default v6 DHCP client port. */ 103 #define ipDHCPv6_CLIENT_PORT 546U 104 /** @brief Default v6 DHCP server port. */ 105 #define ipDHCPv6_SERVER_PORT 547U 106 107 /** @brief The ID of a client or a server. */ 108 typedef struct xClientServerID 109 { 110 uint16_t usDUIDType; /**< A DHCP Unique Identifier ( DUID ). */ 111 uint16_t usHardwareType; /**< The hardware type: 1 = Ethernet. */ 112 uint8_t pucID[ DHCPv6_MAX_CLIENT_SERVER_ID_LENGTH ]; /**< Universally Unique IDentifier (UUID) format. */ 113 size_t uxLength; /**< The number of valid bytes within 'pucID'. */ 114 } ClientServerID_t; 115 116 /** @brief DHCPMessage_IPv6_t holds all data of a DHCP client. */ 117 typedef struct xDHCPMessage_IPv6 118 { 119 uint8_t uxMessageType; /**< The type of the last message received: Advertise / Confirm / Reply / Decline */ 120 uint8_t ucTransactionID[ 3 ]; /**< ID of a transaction, shall be renewed when the transaction is ready ( and a reply has been received ). */ 121 uint32_t ulTransactionID; /**< The same as above but now as a long integer. */ 122 IP_Address_t xDNSServers[ ipconfigENDPOINT_DNS_ADDRESS_COUNT ]; /**< The IP-address of the DNS server. */ 123 size_t uxDNSCount; /**< The number of the DNS server stored in xDNSServers. */ 124 uint32_t ulPreferredLifeTime; /**< The preferred life time. */ 125 uint32_t ulValidLifeTime; /**< The valid life time. */ 126 uint32_t ulTimeStamp; /**< DUID Time: seconds since 1-1-2000. */ 127 uint8_t ucprefixLength; /**< The length of the prefix offered. */ 128 uint8_t ucHasUID; /**< When pdFALSE: a transaction ID must be created. */ 129 IP_Address_t xPrefixAddress; /**< The prefix offered. */ 130 IP_Address_t xIPAddress; /**< The IP-address offered. */ 131 ClientServerID_t xClientID; /**< The UUID of the client. */ 132 ClientServerID_t xServerID; /**< The UUID of the server. */ 133 } DHCPMessage_IPv6_t; 134 135 /** @brief A struct describing an option. */ 136 typedef struct xDHCPOptionSet 137 { 138 size_t uxOptionLength; /**< The length of the option being handled. */ 139 size_t uxStart; /**< The position in xMessage where the option starts. */ 140 } DHCPOptionSet_t; 141 142 struct xNetworkEndPoint; 143 144 /* Returns the current state of a DHCP process. */ 145 eDHCPState_t eGetDHCPv6State( struct xNetworkEndPoint * pxEndPoint ); 146 147 /* 148 * NOT A PUBLIC API FUNCTION. 149 * It will be called when the DHCP timer expires, or when 150 * data has been received on the DHCP socket. 151 */ 152 void vDHCPv6Process( BaseType_t xReset, 153 struct xNetworkEndPoint * pxEndPoint ); 154 155 #ifdef __cplusplus 156 } /* extern "C" */ 157 #endif 158 159 /* The application should supply the following time-function. 160 * It must return the number of seconds that have passed since 161 * 1/1/1970. */ 162 extern uint32_t ulApplicationTimeHook( void ); 163 164 #endif /* FREERTOS_DHCPv6_H */ 165