1 /** 2 * @file 3 * DHCP protocol definitions 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Leon Woestenberg <leon.woestenberg@gmx.net> 8 * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without modification, 12 * are permitted provided that the following conditions are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 * OF SUCH DAMAGE. 32 * 33 * This file is part of the lwIP TCP/IP stack. 34 * 35 * Author: Leon Woestenberg <leon.woestenberg@gmx.net> 36 * 37 */ 38 #ifndef LWIP_HDR_PROT_DHCP_H 39 #define LWIP_HDR_PROT_DHCP_H 40 41 #include "lwip/opt.h" 42 43 #if defined (__cplusplus) && __cplusplus 44 extern "C" { 45 #endif 46 47 #define DHCP_RELAY_PORT LWIP_IANA_PORT_DHCP_SERVER 48 49 /* DHCP message item offsets and length */ 50 #define DHCP_CHADDR_LEN 16U 51 #define DHCP_SNAME_OFS 44U 52 #define DHCP_SNAME_LEN 64U 53 #define DHCP_FILE_OFS 108U 54 #define DHCP_FILE_LEN 128U 55 #define DHCP_MSG_LEN 236U 56 #define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */ 57 58 #ifdef PACK_STRUCT_USE_INCLUDES 59 # include "arch/bpstruct.h" 60 #endif 61 PACK_STRUCT_BEGIN 62 /* minimum set of fields of any DHCP message */ 63 struct dhcp_msg { 64 PACK_STRUCT_FLD_8(u8_t op); 65 PACK_STRUCT_FLD_8(u8_t htype); 66 PACK_STRUCT_FLD_8(u8_t hlen); 67 PACK_STRUCT_FLD_8(u8_t hops); 68 PACK_STRUCT_FIELD(u32_t xid); 69 PACK_STRUCT_FIELD(u16_t secs); 70 PACK_STRUCT_FIELD(u16_t flags); 71 PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr); 72 PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr); 73 PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr); 74 PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr); 75 PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]); 76 PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]); 77 PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]); 78 PACK_STRUCT_FIELD(u32_t cookie); 79 80 #define DHCP_MIN_OPTIONS_LEN 68U 81 82 /* Max length of the vendor class identifier information string can be stored */ 83 #define DHCP_VCI_MAX_LEN 32U 84 85 #if (LWIP_NETIF_HOSTNAME && LWIP_DHCP_VENDOR_CLASS_IDENTIFIER) 86 #define DHCP_MIN_OPTIONS_BUFFER_LEN ((DHCP_MIN_OPTIONS_LEN) + \ 87 (NETIF_HOSTNAME_MAX_LEN) + \ 88 (DHCP_VCI_MAX_LEN) + \ 89 4U) 90 #elif LWIP_NETIF_HOSTNAME 91 /* Minimum option buffer length include: 92 minimum option len + 2 bytes of type/length + max hostname len + 2 bytes padding */ 93 #define DHCP_MIN_OPTIONS_BUFFER_LEN ((DHCP_MIN_OPTIONS_LEN) + \ 94 (NETIF_HOSTNAME_MAX_LEN) + \ 95 4U) 96 #elif LWIP_DHCP_VENDOR_CLASS_IDENTIFIER 97 #define DHCP_MIN_OPTIONS_BUFFER_LEN ((DHCP_MIN_OPTIONS_LEN) + \ 98 (DHCP_VCI_MAX_LEN) + \ 99 4U) 100 #else 101 #define DHCP_MIN_OPTIONS_BUFFER_LEN (DHCP_MIN_OPTIONS_LEN) 102 #endif 103 104 /** make sure user does not configure this too small */ 105 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_BUFFER_LEN)) 106 # undef DHCP_OPTIONS_LEN 107 #endif 108 /* allow this to be configured in lwipopts.h, but not too small */ 109 #if (!defined(DHCP_OPTIONS_LEN)) 110 /* set this to be sufficient for your options in outgoing DHCP msgs */ 111 #define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_BUFFER_LEN 112 #endif 113 PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]); 114 } PACK_STRUCT_STRUCT; 115 PACK_STRUCT_END 116 #ifdef PACK_STRUCT_USE_INCLUDES 117 # include "arch/epstruct.h" 118 #endif 119 120 /* DHCP client states */ 121 typedef enum { 122 DHCP_STATE_OFF = 0, 123 DHCP_STATE_REQUESTING = 1, 124 DHCP_STATE_INIT = 2, 125 DHCP_STATE_REBOOTING = 3, 126 DHCP_STATE_REBINDING = 4, 127 DHCP_STATE_RENEWING = 5, 128 DHCP_STATE_SELECTING = 6, 129 DHCP_STATE_INFORMING = 7, 130 DHCP_STATE_CHECKING = 8, 131 DHCP_STATE_PERMANENT = 9, /* not yet implemented */ 132 DHCP_STATE_BOUND = 10, 133 DHCP_STATE_RELEASING = 11, /* not yet implemented */ 134 DHCP_STATE_BACKING_OFF = 12 135 } dhcp_state_enum_t; 136 137 /* DHCP op codes */ 138 #define DHCP_BOOTREQUEST 1 139 #define DHCP_BOOTREPLY 2 140 141 /* DHCP message types */ 142 #define DHCP_DISCOVER 1 143 #define DHCP_OFFER 2 144 #define DHCP_REQUEST 3 145 #define DHCP_DECLINE 4 146 #define DHCP_ACK 5 147 #define DHCP_NAK 6 148 #define DHCP_RELEASE 7 149 #define DHCP_INFORM 8 150 151 #define DHCP_MAGIC_COOKIE 0x63825363UL 152 153 /* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */ 154 155 /* BootP options */ 156 #define DHCP_OPTION_PAD 0 157 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ 158 #define DHCP_OPTION_SUBNET_MASK_SIZE 4 159 #define DHCP_OPTION_ROUTER 3 160 #define DHCP_OPTION_ROUTER_LEN 4 161 #define DHCP_OPTION_DNS_SERVER 6 162 #define DHCP_OPTION_HOSTNAME 12 163 #define DHCP_OPTION_IP_TTL 23 164 #define DHCP_OPTION_MTU 26 165 #define DHCP_OPTION_BROADCAST 28 166 #define DHCP_OPTION_TCP_TTL 37 167 #define DHCP_OPTION_NTP 42 168 #define DHCP_OPTION_END 255 169 170 /* DHCP options */ 171 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ 172 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ 173 #define DHCP_OPTION_LEASE_TIME_SIZE 4 174 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ 175 176 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ 177 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1 178 179 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ 180 #define DHCP_OPTION_SERVER_ID_LEN 4 181 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ 182 183 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ 184 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 185 186 #define DHCP_OPTION_T1 58 /* T1 renewal time */ 187 #define DHCP_OPTION_T1_LEN 4 188 #define DHCP_OPTION_T2 59 /* T2 rebinding time */ 189 #define DHCP_OPTION_T2_LEN 4 190 #define DHCP_OPTION_VCI 60 191 #define DHCP_OPTION_CLIENT_ID 61 192 #define DHCP_OPTION_CLIENT_ID_LEN 7 193 #define DHCP_OPTION_TFTP_SERVERNAME 66 194 #define DHCP_OPTION_BOOTFILE 67 195 196 #define DHCP_OPTION_AGENT_INFO 82 197 #define DHCP_OPTION_AGENT_INFO_CID 1 198 #define DHCP_OPTION_AGENT_INFO_RID 2 199 200 #define GEN_FLG(name) (1U << (DHCP_OPTION_##name - 32)) 201 202 203 /* possible combinations of overloading the file and sname fields with options */ 204 #define DHCP_OVERLOAD_NONE 0 205 #define DHCP_OVERLOAD_FILE 1 206 #define DHCP_OVERLOAD_SNAME 2 207 #define DHCP_OVERLOAD_SNAME_FILE 3 208 209 #if defined (__cplusplus) && __cplusplus 210 } 211 #endif 212 213 #endif /* LWIP_HDR_PROT_DHCP_H */ 214