Prusa MINI Firmware overview
dhcp.h
Go to the documentation of this file.
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 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #define DHCP_CLIENT_PORT 68
48 #define DHCP_SERVER_PORT 67
49 
50 
51  /* DHCP message item offsets and length */
52 #define DHCP_CHADDR_LEN 16U
53 #define DHCP_SNAME_OFS 44U
54 #define DHCP_SNAME_LEN 64U
55 #define DHCP_FILE_OFS 108U
56 #define DHCP_FILE_LEN 128U
57 #define DHCP_MSG_LEN 236U
58 #define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */
59 
60 #ifdef PACK_STRUCT_USE_INCLUDES
61 # include "arch/bpstruct.h"
62 #endif
64 /** minimum set of fields of any DHCP message */
65 struct dhcp_msg
66 {
68  PACK_STRUCT_FLD_8(u8_t htype);
69  PACK_STRUCT_FLD_8(u8_t hlen);
70  PACK_STRUCT_FLD_8(u8_t hops);
73  PACK_STRUCT_FIELD(u16_t flags);
81  PACK_STRUCT_FIELD(u32_t cookie);
82 #define DHCP_MIN_OPTIONS_LEN 68U
83 /** make sure user does not configure this too small */
84 #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
85 # undef DHCP_OPTIONS_LEN
86 #endif
87 /** allow this to be configured in lwipopts.h, but not too small */
88 #if (!defined(DHCP_OPTIONS_LEN))
89 /** set this to be sufficient for your options in outgoing DHCP msgs */
90 # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
91 #endif
95 #ifdef PACK_STRUCT_USE_INCLUDES
96 # include "arch/epstruct.h"
97 #endif
98 
99 
100 /* DHCP client states */
101 typedef enum {
111  DHCP_STATE_PERMANENT = 9, /* not yet implemented */
113  DHCP_STATE_RELEASING = 11, /* not yet implemented */
116 
117 /* DHCP op codes */
118 #define DHCP_BOOTREQUEST 1
119 #define DHCP_BOOTREPLY 2
120 
121 /* DHCP message types */
122 #define DHCP_DISCOVER 1
123 #define DHCP_OFFER 2
124 #define DHCP_REQUEST 3
125 #define DHCP_DECLINE 4
126 #define DHCP_ACK 5
127 #define DHCP_NAK 6
128 #define DHCP_RELEASE 7
129 #define DHCP_INFORM 8
130 
131 /** DHCP hardware type, currently only ethernet is supported */
132 #define DHCP_HTYPE_ETH 1
133 
134 #define DHCP_MAGIC_COOKIE 0x63825363UL
135 
136 /* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
137 
138 /* BootP options */
139 #define DHCP_OPTION_PAD 0
140 #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
141 #define DHCP_OPTION_ROUTER 3
142 #define DHCP_OPTION_DNS_SERVER 6
143 #define DHCP_OPTION_HOSTNAME 12
144 #define DHCP_OPTION_IP_TTL 23
145 #define DHCP_OPTION_MTU 26
146 #define DHCP_OPTION_BROADCAST 28
147 #define DHCP_OPTION_TCP_TTL 37
148 #define DHCP_OPTION_NTP 42
149 #define DHCP_OPTION_END 255
150 
151 /* DHCP options */
152 #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
153 #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
154 #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
155 
156 #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
157 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
158 
159 #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
160 #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
161 
162 #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
163 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
164 
165 #define DHCP_OPTION_T1 58 /* T1 renewal time */
166 #define DHCP_OPTION_T2 59 /* T2 rebinding time */
167 #define DHCP_OPTION_US 60
168 #define DHCP_OPTION_CLIENT_ID 61
169 #define DHCP_OPTION_TFTP_SERVERNAME 66
170 #define DHCP_OPTION_BOOTFILE 67
171 
172 /* possible combinations of overloading the file and sname fields with options */
173 #define DHCP_OVERLOAD_NONE 0
174 #define DHCP_OVERLOAD_FILE 1
175 #define DHCP_OVERLOAD_SNAME 2
176 #define DHCP_OVERLOAD_SNAME_FILE 3
177 
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif /*LWIP_HDR_PROT_DHCP_H*/
DHCP_STATE_RENEWING
Definition: dhcp.h:107
opt.h
DHCP_STATE_REBOOTING
Definition: dhcp.h:105
DHCP_STATE_REBINDING
Definition: dhcp.h:106
PACK_STRUCT_BEGIN
#define PACK_STRUCT_BEGIN
Definition: arch.h:242
DHCP_STATE_REQUESTING
Definition: dhcp.h:103
bpstruct.h
DHCP_STATE_RELEASING
Definition: dhcp.h:113
u16_t
uint16_t u16_t
Definition: arch.h:121
dhcp_msg
Definition: dhcp.h:65
DHCP_STATE_OFF
Definition: dhcp.h:102
DHCP_CHADDR_LEN
#define DHCP_CHADDR_LEN
Definition: dhcp.h:52
PACK_STRUCT_STRUCT
PACK_STRUCT_BEGIN struct dhcp_msg PACK_STRUCT_STRUCT
DHCP_STATE_BOUND
Definition: dhcp.h:112
u32_t
uint32_t u32_t
Definition: arch.h:123
DHCP_FILE_LEN
#define DHCP_FILE_LEN
Definition: dhcp.h:56
DHCP_OPTIONS_LEN
#define DHCP_OPTIONS_LEN
Definition: dhcp.h:90
dhcp_state_enum_t
dhcp_state_enum_t
Definition: dhcp.h:101
DHCP_STATE_BACKING_OFF
Definition: dhcp.h:114
DHCP_STATE_PERMANENT
Definition: dhcp.h:111
u8_t
uint8_t u8_t
Definition: arch.h:119
DHCP_SNAME_LEN
#define DHCP_SNAME_LEN
Definition: dhcp.h:54
DHCP_STATE_INFORMING
Definition: dhcp.h:109
DHCP_STATE_CHECKING
Definition: dhcp.h:110
dhcp_msg::PACK_STRUCT_FLD_8
PACK_STRUCT_FLD_8(u8_t op)
PACK_STRUCT_END
#define PACK_STRUCT_END
Definition: arch.h:251
DHCP_STATE_INIT
Definition: dhcp.h:104
dhcp_msg::PACK_STRUCT_FLD_S
PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr)
epstruct.h
DHCP_STATE_SELECTING
Definition: dhcp.h:108
dhcp_msg::PACK_STRUCT_FIELD
PACK_STRUCT_FIELD(u32_t xid)
ip4_addr_p_t
typedefPACK_STRUCT_END struct ip4_addr_packed ip4_addr_p_t
Definition: ip4.h:61