Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependents:   STM32F746_iothub_client_sample_mqtt DISCO-F746NG_Ethernet Nucleo_F746ZG_Ethernet thethingsiO-DISCO_F746NG-mqtt ... more

Embed: (wiki syntax)

« Back to documentation index

dhcp.c File Reference

dhcp.c File Reference

Dynamic Host Configuration Protocol client. More...

Go to the source code of this file.

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, 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 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 ()
 The DHCP timer that checks for lease renewal/rebind timeouts.
void dhcp_fine_tmr ()
 DHCP transaction timeout handling.
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, ip_addr_t *addr)
 Match an ARP reply with the offered IP address.
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.
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.

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 dhcp.c.


Function Documentation

void dhcp_arp_reply ( struct netif netif,
ip_addr_t *  addr 
)

Match an ARP reply with the offered IP address.

if enabled, 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 803 of file 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 927 of file 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 225 of file dhcp.c.

void dhcp_cleanup ( struct netif netif )

Removes a struct dhcp from a netif.

ATTENTION: Only use this when not using dhcp_set_struct() to allocate the struct dhcp since the memory is passed back to the heap.

Parameters:
netifthe netif from which to remove the struct dhcp

Definition at line 606 of file dhcp.c.

void dhcp_coarse_tmr ( void   )

The DHCP timer that checks for lease renewal/rebind timeouts.

to be called every minute

Definition at line 337 of file 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 1641 of file 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 832 of file 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 1735 of file 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 872 of file dhcp.c.

void dhcp_fine_tmr ( void   )

DHCP transaction timeout handling.

to be called every half second

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 369 of file 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 508 of file 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 197 of file 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 252 of file dhcp.c.

void dhcp_inform ( struct netif netif )

Inform a DHCP server of our manual configuration.

inform server of our manual IP address

This informs DHCP servers of our fixed IP address configuration by sending an INFORM message. It does not involve DHCP address configuration, it is just here to be nice to the network.

Parameters:
netifThe lwIP network interface

Definition at line 712 of file 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 766 of file 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 1756 of file 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 conitguous piece of memory, and use that further on.

Definition at line 1337 of file 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 1076 of file 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 1126 of file dhcp.c.

static void dhcp_recv ( void *  arg,
struct udp_pcb *  pcb,
struct pbuf *  p,
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 1537 of file dhcp.c.

err_t dhcp_release ( struct netif netif )

Release a DHCP lease.

release the DHCP lease, usually called before dhcp_stop()

Parameters:
netifnetwork interface which must release its lease

Definition at line 1168 of file dhcp.c.

err_t dhcp_renew ( struct netif netif )

Renew an existing DHCP lease at the involved DHCP server.

enforce early lease renewal (not needed normally)

Parameters:
netifnetwork interface which must renew its lease

Definition at line 1022 of file 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 283 of file dhcp.c.

void dhcp_set_struct ( struct netif netif,
struct dhcp *  dhcp 
)

Set a statically allocated struct dhcp to work with.

Using this prevents dhcp_start to allocate it using mem_malloc.

Parameters:
netifthe netif for which to set the struct dhcp
dhcp(uninitialised) dhcp struct allocated by the application

Definition at line 587 of file dhcp.c.

err_t dhcp_start ( struct netif netif )

Start DHCP negotiation for a network interface.

start DHCP configuration

If no DHCP client instance was attached to this interface, a new client is created first. If a DHCP client instance was already present, it restarts negotiation.

Parameters:
netifThe lwIP network interface
Returns:
lwIP error code
  • ERR_OK - No error
  • ERR_MEM - Out of memory

Definition at line 629 of file dhcp.c.

void dhcp_stop ( struct netif netif )

Remove the DHCP client from the interface.

stop DHCP configuration

Parameters:
netifThe network interface to stop DHCP on

Definition at line 1220 of file 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 465 of file 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 487 of file 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 402 of file 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 133 of file 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 129 of file dhcp.c.