Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 struct pbuf * | dhcp_create_msg (struct netif *netif, struct dhcp *dhcp, u8_t message_type, u16_t *options_out_len) |
Create a DHCP request, fill in common headers. | |
static void | dhcp_option_trailer (u16_t options_out_len, u8_t *options, struct pbuf *p_out) |
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, struct dhcp_msg *msg_in) |
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, struct dhcp_msg *msg_in) |
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. | |
void | dhcp_release_and_stop (struct netif *netif) |
Release a DHCP lease and stop DHCP statemachine (and AUTOIP if LWIP_DHCP_AUTOIP_COOP). | |
err_t | dhcp_release (struct netif *netif) |
This function calls dhcp_release_and_stop() internally. | |
void | dhcp_stop (struct netif *netif) |
This function calls dhcp_release_and_stop() internally. | |
static err_t | dhcp_parse_reply (struct pbuf *p, struct dhcp *dhcp) |
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
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.
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 135 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:
-
netif the network interface on which the reply was received addr The IP address we received a reply from
Definition at line 903 of file lwip_dhcp.c.
static void dhcp_bind | ( | struct netif * | netif ) | [static] |
Bind the interface to the offered IP address.
- Parameters:
-
netif network interface to bind to the offered address
Definition at line 1040 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:
-
netif the netif under DHCP control
Definition at line 303 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 430 of file lwip_dhcp.c.
static struct pbuf * dhcp_create_msg | ( | struct netif * | netif, |
struct dhcp * | dhcp, | ||
u8_t | message_type, | ||
u16_t * | options_out_len | ||
) | [static, read] |
Create a DHCP request, fill in common headers.
- Parameters:
-
netif the netif under DHCP control dhcp dhcp control struct message_type message 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 1874 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 253 of file lwip_dhcp.c.
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:
-
netif the netif under DHCP control
Definition at line 935 of file lwip_dhcp.c.
Start the DHCP process, discover a DHCP server.
- Parameters:
-
netif the netif under DHCP control
Definition at line 981 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 468 of file lwip_dhcp.c.
Handle a DHCP ACK packet.
- Parameters:
-
netif the netif under DHCP control
Definition at line 599 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:
-
netif the netif under DHCP control
Definition at line 277 of file lwip_dhcp.c.
Remember the configuration offered by a DHCP server.
- Parameters:
-
netif the netif under DHCP control
Definition at line 332 of file lwip_dhcp.c.
static err_t dhcp_inc_pcb_refcount | ( | void | ) | [static] |
Ensure DHCP PCB is allocated and bound.
Definition at line 226 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 858 of file lwip_dhcp.c.
static void dhcp_option_trailer | ( | u16_t | options_out_len, |
u8_t * | options, | ||
struct pbuf * | p_out | ||
) | [static] |
Add a DHCP message trailer.
Adds the END option to the DHCP message, and if necessary, up to three padding bytes.
Definition at line 1960 of file lwip_dhcp.c.
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 1507 of file lwip_dhcp.c.
Rebind with a DHCP server for an existing DHCP lease.
- Parameters:
-
netif network interface which must rebind with a DHCP server
Definition at line 1206 of file lwip_dhcp.c.
Enter REBOOTING state to verify an existing lease.
- Parameters:
-
netif network interface which must reboot
Definition at line 1260 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 1754 of file lwip_dhcp.c.
Select a DHCP server offer out of all offers.
Simply select the first offer received.
- Parameters:
-
netif the netif under DHCP control
- Returns:
- lwIP specific error (see error.h)
Definition at line 366 of file lwip_dhcp.c.
u8_t dhcp_supplied_address | ( | const struct netif * | netif ) |
check if DHCP supplied netif->ip_addr
- Parameters:
-
netif the netif to check
- Returns:
- 1 if DHCP supplied netif->ip_addr (states BOUND or RENEWING), 0 otherwise
Definition at line 1980 of file lwip_dhcp.c.
static void dhcp_t1_timeout | ( | struct netif * | netif ) | [static] |
The renewal period has timed out.
- Parameters:
-
netif the netif under DHCP control
Definition at line 546 of file lwip_dhcp.c.
static void dhcp_t2_timeout | ( | struct netif * | netif ) | [static] |
The rebind period has timed out.
- Parameters:
-
netif the netif under DHCP control
Definition at line 573 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:
-
netif the netif under DHCP control
Definition at line 499 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 161 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 157 of file lwip_dhcp.c.
Generated on Tue Jul 12 2022 13:55:13 by
