Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

lwip_dhcp.c File Reference

lwip_dhcp.c File Reference

Dynamic Host Configuration Protocol client. More...

Go to the source code of this file.

Enumerations

enum  dhcp_option_idx
 

Option handling: options are parsed in dhcp_parse_reply and saved in an array where other functions can load them from.

More...

Functions

static err_t dhcp_discover (struct netif *netif)
 Start the DHCP process, discover a DHCP server.
static err_t dhcp_select (struct netif *netif)
 Select a DHCP server offer out of all offers.
static void dhcp_bind (struct netif *netif)
 Bind the interface to the offered IP address.
static err_t dhcp_decline (struct netif *netif)
 Decline an offered lease.
static err_t dhcp_rebind (struct netif *netif)
 Rebind with a DHCP server for an existing DHCP lease.
static err_t dhcp_reboot (struct netif *netif)
 Enter REBOOTING state to verify an existing lease.
static void dhcp_recv (void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
 If an incoming DHCP message is in response to us, then trigger the state machine.
static void dhcp_timeout (struct netif *netif)
 A DHCP negotiation transaction, or ARP request, has timed out.
static void dhcp_t1_timeout (struct netif *netif)
 The renewal period has timed out.
static void dhcp_t2_timeout (struct netif *netif)
 The rebind period has timed out.
static err_t dhcp_create_msg (struct netif *netif, struct dhcp *dhcp, u8_t message_type)
 Create a DHCP request, fill in common headers.
static void dhcp_delete_msg (struct dhcp *dhcp)
 Free previously allocated memory used to send a DHCP request.
static void dhcp_option_trailer (struct dhcp *dhcp)
 Add a DHCP message trailer.
static err_t dhcp_inc_pcb_refcount (void)
 Ensure DHCP PCB is allocated and bound.
static void dhcp_dec_pcb_refcount (void)
 Free DHCP PCB if the last netif stops using it.
static void dhcp_handle_nak (struct netif *netif)
 Back-off the DHCP client (because of a received NAK response).
static void dhcp_check (struct netif *netif)
 Checks if the offered IP address is already in use.
static void dhcp_handle_offer (struct netif *netif)
 Remember the configuration offered by a DHCP server.
void dhcp_coarse_tmr (void)
 The DHCP timer that checks for lease renewal/rebind timeouts.
void dhcp_fine_tmr (void)
 DHCP transaction timeout handling (this function must be called every 500ms, see DHCP_FINE_TIMER_MSECS).
static void dhcp_handle_ack (struct netif *netif)
 Handle a DHCP ACK packet.
void dhcp_set_struct (struct netif *netif, struct dhcp *dhcp)
 Set a statically allocated struct dhcp to work with.
void dhcp_cleanup (struct netif *netif)
 Removes a struct dhcp from a netif.
err_t dhcp_start (struct netif *netif)
 Start DHCP negotiation for a network interface.
void dhcp_inform (struct netif *netif)
 Inform a DHCP server of our manual configuration.
void dhcp_network_changed (struct netif *netif)
 Handle a possible change in the network configuration.
void dhcp_arp_reply (struct netif *netif, const ip4_addr_t *addr)
 Match an ARP reply with the offered IP address: check whether the offered IP address is not in use using ARP.
err_t dhcp_renew (struct netif *netif)
 Renew an existing DHCP lease at the involved DHCP server.
err_t dhcp_release (struct netif *netif)
 Release a DHCP lease (usually called before dhcp_stop).
void dhcp_stop (struct netif *netif)
 Remove the DHCP client from the interface.
static err_t dhcp_parse_reply (struct dhcp *dhcp, struct pbuf *p)
 Extract the DHCP message and the DHCP options.
u8_t dhcp_supplied_address (const struct netif *netif)
 check if DHCP supplied netif->ip_addr

Variables

u32_t dhcp_rx_options_val [DHCP_OPTION_IDX_MAX]
 Holds the decoded option values, only valid while in dhcp_recv.
u8_t dhcp_rx_options_given [DHCP_OPTION_IDX_MAX]
 Holds a flag which option was received and is contained in dhcp_rx_options_val, only valid while in dhcp_recv.

Detailed Description

Dynamic Host Configuration Protocol client.

Definition in file lwip_dhcp.c.


Enumeration Type Documentation

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).

Definition at line 121 of file lwip_dhcp.c.


Function Documentation

void dhcp_arp_reply ( struct netif netif,
const ip4_addr_t addr 
)

Match an ARP reply with the offered IP address: check whether the offered IP address is not in use using ARP.

Parameters:
netifthe network interface on which the reply was received
addrThe IP address we received a reply from

Definition at line 887 of file lwip_dhcp.c.

static void dhcp_bind ( struct netif netif ) [static]

Bind the interface to the offered IP address.

Parameters:
netifnetwork interface to bind to the offered address

Definition at line 1017 of file lwip_dhcp.c.

static void dhcp_check ( struct netif netif ) [static]

Checks if the offered IP address is already in use.

It does so by sending an ARP request for the offered address and entering CHECKING state. If no ARP reply is received within a small interval, the address is assumed to be free for use by us.

Parameters:
netifthe netif under DHCP control

Definition at line 291 of file lwip_dhcp.c.

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).

Definition at line 409 of file lwip_dhcp.c.

static err_t dhcp_create_msg ( struct netif netif,
struct dhcp *  dhcp,
u8_t  message_type 
) [static]

Create a DHCP request, fill in common headers.

Parameters:
netifthe netif under DHCP control
dhcpdhcp control struct
message_typemessage type of the request

default global transaction identifier starting value (easy to match with a packet analyser). We simply increment for each new request. Predefine DHCP_GLOBAL_XID to a better value or a function call to generate one at runtime, any supporting function prototypes can be defined in DHCP_GLOBAL_XID_HEADER

Definition at line 1802 of file lwip_dhcp.c.

static void dhcp_dec_pcb_refcount ( void   ) [static]

Free DHCP PCB if the last netif stops using it.

Definition at line 241 of file lwip_dhcp.c.

static err_t dhcp_decline ( struct netif netif ) [static]

Decline an offered lease.

Tell the DHCP server we do not accept the offered address. One reason to decline the lease is when we find out the address is already in use by another host (through ARP).

Parameters:
netifthe netif under DHCP control

Definition at line 919 of file lwip_dhcp.c.

static void dhcp_delete_msg ( struct dhcp *  dhcp ) [static]

Free previously allocated memory used to send a DHCP request.

Parameters:
dhcpthe dhcp struct to free the request from

Definition at line 1899 of file lwip_dhcp.c.

static err_t dhcp_discover ( struct netif netif ) [static]

Start the DHCP process, discover a DHCP server.

Parameters:
netifthe netif under DHCP control

Definition at line 961 of file lwip_dhcp.c.

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.

Definition at line 449 of file lwip_dhcp.c.

static void dhcp_handle_ack ( struct netif netif ) [static]

Handle a DHCP ACK packet.

Parameters:
netifthe netif under DHCP control

Definition at line 585 of file lwip_dhcp.c.

static void dhcp_handle_nak ( struct netif netif ) [static]

Back-off the DHCP client (because of a received NAK response).

Back-off the DHCP client because of a received NAK. Receiving a NAK means the client asked for something non-sensible, for example when it tries to renew a lease obtained on another network.

We clear any existing set IP address and restart DHCP negotiation afresh (as per RFC2131 3.2.3).

Parameters:
netifthe netif under DHCP control

Definition at line 265 of file lwip_dhcp.c.

static void dhcp_handle_offer ( struct netif netif ) [static]

Remember the configuration offered by a DHCP server.

Parameters:
netifthe netif under DHCP control

Definition at line 320 of file lwip_dhcp.c.

static err_t dhcp_inc_pcb_refcount ( void   ) [static]

Ensure DHCP PCB is allocated and bound.

Definition at line 214 of file lwip_dhcp.c.

void dhcp_network_changed ( 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.

Definition at line 844 of file lwip_dhcp.c.

static void dhcp_option_trailer ( struct dhcp *  dhcp ) [static]

Add a DHCP message trailer.

Adds the END option to the DHCP message, and if necessary, up to three padding bytes.

Parameters:
dhcpDHCP state structure

Definition at line 1920 of file lwip_dhcp.c.

static err_t dhcp_parse_reply ( struct dhcp *  dhcp,
struct pbuf p 
) [static]

Extract the DHCP message and the DHCP options.

Extract the DHCP message and the DHCP options, each into a contiguous piece of memory. As a DHCP message is variable sized by its options, and also allows overriding some fields for options, the easy approach is to first unfold the options into a contiguous piece of memory, and use that further on.

Definition at line 1460 of file lwip_dhcp.c.

static err_t dhcp_rebind ( struct netif netif ) [static]

Rebind with a DHCP server for an existing DHCP lease.

Parameters:
netifnetwork interface which must rebind with a DHCP server

Definition at line 1179 of file lwip_dhcp.c.

static err_t dhcp_reboot ( struct netif netif ) [static]

Enter REBOOTING state to verify an existing lease.

Parameters:
netifnetwork interface which must reboot

Definition at line 1229 of file lwip_dhcp.c.

static void dhcp_recv ( void *  arg,
struct udp_pcb pcb,
struct pbuf p,
const ip_addr_t addr,
u16_t  port 
) [static]

If an incoming DHCP message is in response to us, then trigger the state machine.

Definition at line 1678 of file lwip_dhcp.c.

static err_t dhcp_select ( struct netif netif ) [static]

Select a DHCP server offer out of all offers.

Simply select the first offer received.

Parameters:
netifthe netif under DHCP control
Returns:
lwIP specific error (see error.h)

Definition at line 352 of file lwip_dhcp.c.

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

Definition at line 1941 of file lwip_dhcp.c.

static void dhcp_t1_timeout ( struct netif netif ) [static]

The renewal period has timed out.

Parameters:
netifthe netif under DHCP control

Definition at line 530 of file lwip_dhcp.c.

static void dhcp_t2_timeout ( struct netif netif ) [static]

The rebind period has timed out.

Parameters:
netifthe netif under DHCP control

Definition at line 558 of file lwip_dhcp.c.

static void dhcp_timeout ( struct netif netif ) [static]

A DHCP negotiation transaction, or ARP request, has timed out.

The timer that was started with the DHCP or ARP request has timed out, indicating no response was received in time.

Parameters:
netifthe netif under DHCP control

Definition at line 483 of file lwip_dhcp.c.


Variable Documentation

u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX]

Holds a flag which option was received and is contained in dhcp_rx_options_val, only valid while in dhcp_recv.

Definition at line 147 of file lwip_dhcp.c.

u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX]

Holds the decoded option values, only valid while in dhcp_recv.

Definition at line 143 of file lwip_dhcp.c.