summaryrefslogtreecommitdiff
path: root/core/lwip/src/include/lwip/dhcp.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/lwip/src/include/lwip/dhcp.h')
-rw-r--r--core/lwip/src/include/lwip/dhcp.h156
1 files changed, 76 insertions, 80 deletions
diff --git a/core/lwip/src/include/lwip/dhcp.h b/core/lwip/src/include/lwip/dhcp.h
index db37e884..32d93381 100644
--- a/core/lwip/src/include/lwip/dhcp.h
+++ b/core/lwip/src/include/lwip/dhcp.h
@@ -22,6 +22,10 @@ extern "C" {
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */
#define DHCP_FINE_TIMER_MSECS 500
+#define DHCP_CHADDR_LEN 16U
+#define DHCP_SNAME_LEN 64U
+#define DHCP_FILE_LEN 128U
+
struct dhcp
{
/** transaction identifier of last sent request */
@@ -30,14 +34,14 @@ struct dhcp
struct udp_pcb *pcb;
/** incoming msg */
struct dhcp_msg *msg_in;
- /** incoming msg options */
- void *options_in;
- /** ingoing msg options length */
- u16_t options_in_len;
/** current DHCP state machine state */
u8_t state;
/** retries of current request */
u8_t tries;
+#if LWIP_DHCP_AUTOIP_COOP
+ u8_t autoip_coop_state;
+#endif
+ u8_t subnet_mask_given;
struct pbuf *p_out; /* pbuf of outcoming msg */
struct dhcp_msg *msg_out; /* outgoing msg */
@@ -45,28 +49,20 @@ struct dhcp
u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
- struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
- struct ip_addr offered_ip_addr;
- struct ip_addr offered_sn_mask;
- struct ip_addr offered_gw_addr;
- struct ip_addr offered_bc_addr;
-#define DHCP_MAX_DNS 2
- u32_t dns_count; /* actual number of DNS servers obtained */
- struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
+ ip_addr_t server_ip_addr; /* dhcp server address that offered this lease */
+ ip_addr_t offered_ip_addr;
+ ip_addr_t offered_sn_mask;
+ ip_addr_t offered_gw_addr;
u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
-#if LWIP_DHCP_AUTOIP_COOP
- u8_t autoip_coop_state;
-#endif
-/** Patch #1308
- * TODO: See dhcp.c "TODO"s
- */
-#if 0
- struct ip_addr offered_si_addr;
- u8_t *boot_file_name;
-#endif
+ /* @todo: LWIP_DHCP_BOOTP_FILE configuration option?
+ integrate with possible TFTP-client for booting? */
+#if LWIP_DHCP_BOOTP_FILE
+ ip_addr_t offered_si_addr;
+ char boot_file_name[DHCP_FILE_LEN];
+#endif /* LWIP_DHCP_BOOTPFILE */
};
/* MUST be compiled with "pack structs" or equivalent! */
@@ -84,15 +80,12 @@ struct dhcp_msg
PACK_STRUCT_FIELD(u32_t xid);
PACK_STRUCT_FIELD(u16_t secs);
PACK_STRUCT_FIELD(u16_t flags);
- PACK_STRUCT_FIELD(struct ip_addr ciaddr);
- PACK_STRUCT_FIELD(struct ip_addr yiaddr);
- PACK_STRUCT_FIELD(struct ip_addr siaddr);
- PACK_STRUCT_FIELD(struct ip_addr giaddr);
-#define DHCP_CHADDR_LEN 16U
+ PACK_STRUCT_FIELD(ip_addr_p_t ciaddr);
+ PACK_STRUCT_FIELD(ip_addr_p_t yiaddr);
+ PACK_STRUCT_FIELD(ip_addr_p_t siaddr);
+ PACK_STRUCT_FIELD(ip_addr_p_t giaddr);
PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
-#define DHCP_SNAME_LEN 64U
PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
-#define DHCP_FILE_LEN 128U
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
PACK_STRUCT_FIELD(u32_t cookie);
#define DHCP_MIN_OPTIONS_LEN 68U
@@ -112,6 +105,10 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
+void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
+/** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */
+#define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0)
+void dhcp_cleanup(struct netif *netif);
/** start DHCP configuration */
err_t dhcp_start(struct netif *netif);
/** enforce early lease renewal (not needed normally)*/
@@ -127,7 +124,7 @@ void dhcp_network_changed(struct netif *netif);
/** if enabled, check whether the offered IP address is not in use, using ARP */
#if DHCP_DOES_ARP_CHECK
-void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
+void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr);
#endif
/** to be called every minute */
@@ -136,66 +133,66 @@ void dhcp_coarse_tmr(void);
void dhcp_fine_tmr(void);
/** DHCP message item offsets and length */
-#define DHCP_MSG_OFS (UDP_DATA_OFS)
- #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
- #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
- #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
- #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
- #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
- #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
- #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
- #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
- #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
- #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
- #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
- #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
- #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
- #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
-#define DHCP_MSG_LEN 236
-
-#define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
-#define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
-
-#define DHCP_CLIENT_PORT 68
-#define DHCP_SERVER_PORT 67
+#define DHCP_OP_OFS 0
+#define DHCP_HTYPE_OFS 1
+#define DHCP_HLEN_OFS 2
+#define DHCP_HOPS_OFS 3
+#define DHCP_XID_OFS 4
+#define DHCP_SECS_OFS 8
+#define DHCP_FLAGS_OFS 10
+#define DHCP_CIADDR_OFS 12
+#define DHCP_YIADDR_OFS 16
+#define DHCP_SIADDR_OFS 20
+#define DHCP_GIADDR_OFS 24
+#define DHCP_CHADDR_OFS 28
+#define DHCP_SNAME_OFS 44
+#define DHCP_FILE_OFS 108
+#define DHCP_MSG_LEN 236
+
+#define DHCP_COOKIE_OFS DHCP_MSG_LEN
+#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4)
+
+#define DHCP_CLIENT_PORT 68
+#define DHCP_SERVER_PORT 67
/** DHCP client states */
-#define DHCP_REQUESTING 1
-#define DHCP_INIT 2
-#define DHCP_REBOOTING 3
-#define DHCP_REBINDING 4
-#define DHCP_RENEWING 5
-#define DHCP_SELECTING 6
-#define DHCP_INFORMING 7
-#define DHCP_CHECKING 8
-#define DHCP_PERMANENT 9
-#define DHCP_BOUND 10
+#define DHCP_OFF 0
+#define DHCP_REQUESTING 1
+#define DHCP_INIT 2
+#define DHCP_REBOOTING 3
+#define DHCP_REBINDING 4
+#define DHCP_RENEWING 5
+#define DHCP_SELECTING 6
+#define DHCP_INFORMING 7
+#define DHCP_CHECKING 8
+#define DHCP_PERMANENT 9
+#define DHCP_BOUND 10
/** not yet implemented #define DHCP_RELEASING 11 */
-#define DHCP_BACKING_OFF 12
-#define DHCP_OFF 13
+#define DHCP_BACKING_OFF 12
/** AUTOIP cooperatation flags */
-#define DHCP_AUTOIP_COOP_STATE_OFF 0
-#define DHCP_AUTOIP_COOP_STATE_ON 1
+#define DHCP_AUTOIP_COOP_STATE_OFF 0
+#define DHCP_AUTOIP_COOP_STATE_ON 1
-#define DHCP_BOOTREQUEST 1
-#define DHCP_BOOTREPLY 2
+#define DHCP_BOOTREQUEST 1
+#define DHCP_BOOTREPLY 2
+/** DHCP message types */
#define DHCP_DISCOVER 1
-#define DHCP_OFFER 2
-#define DHCP_REQUEST 3
-#define DHCP_DECLINE 4
-#define DHCP_ACK 5
-#define DHCP_NAK 6
-#define DHCP_RELEASE 7
-#define DHCP_INFORM 8
-
+#define DHCP_OFFER 2
+#define DHCP_REQUEST 3
+#define DHCP_DECLINE 4
+#define DHCP_ACK 5
+#define DHCP_NAK 6
+#define DHCP_RELEASE 7
+#define DHCP_INFORM 8
+
+/** DHCP hardware type, currently only ethernet is supported */
#define DHCP_HTYPE_ETH 1
-#define DHCP_HLEN_ETH 6
+#define DHCP_MAGIC_COOKIE 0x63825363UL
-#define DHCP_BROADCAST_FLAG 15
-#define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
+/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */
/** BootP options */
#define DHCP_OPTION_PAD 0
@@ -217,7 +214,6 @@ void dhcp_fine_tmr(void);
#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
#define DHCP_OPTION_MESSAGE_TYPE_LEN 1
-
#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */