lwIP 2.2.0
Lightweight IP stack
Loading...
Searching...
No Matches
dhcp.c File Reference
#include "lwip/opt.h"
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/def.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/acd.h"
#include "lwip/dns.h"
#include "lwip/etharp.h"
#include "lwip/prot/dhcp.h"
#include "lwip/prot/iana.h"
#include <string.h>
#include "path/to/my/lwip_hooks.h"

Macros

#define DHCP_ADD_EXTRA_REQUEST_OPTIONS
 
#define SET_TIMEOUT_FROM_OFFERED(result, offered, min, max)
 
#define DHCP_CREATE_RAND_XID   1
 
#define DHCP_MAX_MSG_LEN(netif)   (netif->mtu)
 
#define DHCP_MIN_REPLY_LEN   44
 

Enumerations

enum  dhcp_option_idx
 

Functions

void dhcp_coarse_tmr (void)
 
void dhcp_fine_tmr (void)
 
void dhcp_set_struct (struct netif *netif, struct dhcp *dhcp)
 
void dhcp_cleanup (struct netif *netif)
 
err_t dhcp_start (struct netif *netif)
 
void dhcp_inform (struct netif *netif)
 
void dhcp_network_changed_link_up (struct netif *netif)
 
err_t dhcp_renew (struct netif *netif)
 
void dhcp_release_and_stop (struct netif *netif)
 
err_t dhcp_release (struct netif *netif)
 
void dhcp_stop (struct netif *netif)
 
u8_t dhcp_supplied_address (const struct netif *netif)
 

Detailed Description

Dynamic Host Configuration Protocol client

Macro Definition Documentation

◆ DHCP_ADD_EXTRA_REQUEST_OPTIONS

#define DHCP_ADD_EXTRA_REQUEST_OPTIONS

DHCP_ADD_EXTRA_REQUEST_OPTIONS: Additional options added to the list of options that the client requests from the servers (opt 55: DHCP_OPTION_PARAMETER_REQUEST_LIST) If additional options are requested, define this macro as a comma separated list, with leading comma. This macro is useful for example when requested vendor specific ids (VCI/VSI options), here is an example of requesting the VSI option (option 43) (yes, the notation is a bit strange, but it works :) (NOTE: the space between # and define is required because of doxygen...)

define DHCP_ADD_EXTRA_REQUEST_OPTIONS ,43

◆ DHCP_CREATE_RAND_XID

#define DHCP_CREATE_RAND_XID   1

DHCP_CREATE_RAND_XID: if this is set to 1, the xid is created using LWIP_RAND() (this overrides DHCP_GLOBAL_XID)

◆ DHCP_MAX_MSG_LEN

#define DHCP_MAX_MSG_LEN (   netif)    (netif->mtu)

Default for DHCP_GLOBAL_XID is 0xABCD0000 This can be changed by defining DHCP_GLOBAL_XID and DHCP_GLOBAL_XID_HEADER, e.g. #define DHCP_GLOBAL_XID_HEADER "stdlib.h" #define DHCP_GLOBAL_XID rand() DHCP_OPTION_MAX_MSG_SIZE is set to the MTU MTU is checked to be big enough in dhcp_start

◆ DHCP_MIN_REPLY_LEN

#define DHCP_MIN_REPLY_LEN   44

Minimum length for reply before packet is parsed

◆ SET_TIMEOUT_FROM_OFFERED

#define SET_TIMEOUT_FROM_OFFERED (   result,
  offered,
  min,
  max 
)
Value:
do { \
u32_t timeout = (offered + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; \
if (timeout > max) { \
timeout = max; \
} \
if (timeout == min) { \
timeout = 1; \
} \
result = (dhcp_timeout_t)timeout; \
} while(0)
#define DHCP_COARSE_TIMER_SECS
Definition dhcp.h:65
u16_t dhcp_timeout_t
Definition dhcp.h:61

DHCP_DEFINE_CUSTOM_TIMEOUTS: if this is defined then you can customize various DHCP timeouts using these macros:

  • DHCP_SET_TIMEOUT_FROM_OFFERED_T0_LEASE() to adjust the t0 lease timeout from the offered value
  • DHCP_SET_TIMEOUT_FROM_OFFERED_T1_RENEW() same for t1 renew
  • DHCP_SET_TIMEOUT_FROM_OFFERED_T2_REBIND() same for t2 rebind
  • DHCP_NEXT_TIMEOUT_THRESHOLD to adjust the period of the next timeout
  • DHCP_REQUEST_BACKOFF_SEQUENCE to adjust back-off times based on DHCP request attempts

Enumeration Type Documentation

◆ dhcp_option_idx

Option handling: options are parsed in dhcp_parse_reply and saved in an array where other functions can load them from. This might be moved into the struct dhcp (not necessarily since lwIP is single-threaded and the array is only used while in recv callback).

Function Documentation

◆ dhcp_coarse_tmr()

void dhcp_coarse_tmr ( void  )

The DHCP timer that checks for lease renewal/rebind timeouts. Must be called once a minute (see DHCP_COARSE_TIMER_SECS).

◆ dhcp_fine_tmr()

void dhcp_fine_tmr ( void  )

DHCP transaction timeout handling (this function must be called every 500ms, see DHCP_FINE_TIMER_MSECS).

A DHCP server is expected to respond within a short period of time. This timer checks whether an outstanding DHCP request is timed out.

◆ dhcp_network_changed_link_up()

void dhcp_network_changed_link_up ( struct netif netif)

Handle a possible change in the network configuration.

This enters the REBOOTING state to verify that the currently bound address is still valid.

◆ dhcp_supplied_address()

u8_t dhcp_supplied_address ( const struct netif netif)

check if DHCP supplied netif->ip_addr

Parameters
netifthe netif to check
Returns
1 if DHCP supplied netif->ip_addr (states BOUND or RENEWING), 0 otherwise