Microchip® Advanced Software Framework

autoip.c File Reference

AutoIP Automatic LinkLocal IP Configuration.

#include "lwip/opt.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/autoip.h"
#include "netif/etharp.h"
#include <stdlib.h>
#include <string.h>

Macros

#define AUTOIP_NET   0xA9FE0000
 
#define AUTOIP_RANGE_END   (AUTOIP_NET | 0xFEFF)
 
#define AUTOIP_RANGE_START   (AUTOIP_NET | 0x0100)
 
#define LWIP_AUTOIP_CREATE_SEED_ADDR(netif)
 Macro that generates the initial IP address to be tried by AUTOIP. More...
 
#define LWIP_AUTOIP_RAND(netif)
 Pseudo random macro based on netif informations. More...
 

Functions

static err_t autoip_arp_announce (struct netif *netif)
 Sends an ARP announce from a network interface. More...
 
static err_t autoip_arp_probe (struct netif *netif)
 Sends an ARP probe from a network interface. More...
 
void autoip_arp_reply (struct netif *netif, struct etharp_hdr *hdr)
 Handles every incoming ARP Packet, called by etharp_arp_input. More...
 
static err_t autoip_bind (struct netif *netif)
 Configure interface for use with current LL IP-Address. More...
 
static void autoip_create_addr (struct netif *netif, ip_addr_t *ipaddr)
 Create an IP-Address out of range 169.254.1.0 to 169.254.254.255. More...
 
static void autoip_handle_arp_conflict (struct netif *netif)
 Handle a IP address conflict after an ARP conflict detection. More...
 
void autoip_network_changed (struct netif *netif)
 Handle a possible change in the network configuration. More...
 
static void autoip_restart (struct netif *netif)
 Restart AutoIP client and check the next address (conflict detected) More...
 
void autoip_set_struct (struct netif *netif, struct autoip *autoip)
 Set a statically allocated struct autoip to work with. More...
 
err_t autoip_start (struct netif *netif)
 Start AutoIP client. More...
 
static void autoip_start_probing (struct netif *netif)
 
err_t autoip_stop (struct netif *netif)
 Stop AutoIP client. More...
 
void autoip_tmr ()
 Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds. More...
 

#define AUTOIP_NET   0xA9FE0000

Referenced by autoip_create_addr().

#define AUTOIP_RANGE_END   (AUTOIP_NET | 0xFEFF)

Referenced by autoip_create_addr().

#define AUTOIP_RANGE_START   (AUTOIP_NET | 0x0100)

Referenced by autoip_create_addr().

#define LWIP_AUTOIP_CREATE_SEED_ADDR (   netif)
Value:
((u32_t)((u8_t)(netif->hwaddr[5]))) << 8)))
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
link level hardware address of this interface
Definition: netif.h:239
#define AUTOIP_RANGE_START
Definition: autoip.c:82
Generic data structure used for all lwIP network interfaces.
Definition: netif.h:160
unsigned int u32_t
Definition: cc.h:49
unsigned char u8_t
Definition: cc.h:47
#define htonl(x)
Definition: def.h:79

Macro that generates the initial IP address to be tried by AUTOIP.

If you want to override this, define it to something else in lwipopts.h.

Referenced by autoip_create_addr().

#define LWIP_AUTOIP_RAND (   netif)
Value:
( (((u32_t)((netif->hwaddr[5]) & 0xff) << 24) | \
((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \
((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \
((u32_t)((netif->hwaddr[4]) & 0xff))) + \
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
link level hardware address of this interface
Definition: netif.h:239
u8_t tried_llipaddr
Definition: autoip.h:88
struct autoip * autoip
the AutoIP client state information for this netif
Definition: netif.h:216
Generic data structure used for all lwIP network interfaces.
Definition: netif.h:160
unsigned int u32_t
Definition: cc.h:49

Pseudo random macro based on netif informations.

You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h

Referenced by autoip_start_probing(), and autoip_tmr().

static err_t autoip_arp_announce ( struct netif netif)
static

Sends an ARP announce from a network interface.

Parameters
netifnetwork interface used to send the announce

References ARP_REQUEST, netif::autoip, etharp_raw(), ethbroadcast, ethzero, netif::hwaddr, and autoip::llipaddr.

Referenced by autoip_handle_arp_conflict(), and autoip_tmr().

static err_t autoip_arp_probe ( struct netif netif)
static

Sends an ARP probe from a network interface.

Parameters
netifnetwork interface used to send the probe

References ARP_REQUEST, netif::autoip, etharp_raw(), ethbroadcast, ethzero, netif::hwaddr, IP_ADDR_ANY, and autoip::llipaddr.

Referenced by autoip_tmr().

void autoip_arp_reply ( struct netif netif,
struct etharp_hdr hdr 
)

Handles every incoming ARP Packet, called by etharp_arp_input.

Parameters
netifnetwork interface to use for autoip processing
hdrIncoming ARP packet

References netif::autoip, AUTOIP_DEBUG, autoip_handle_arp_conflict(), autoip_restart(), AUTOIP_STATE_ANNOUNCING, AUTOIP_STATE_OFF, AUTOIP_STATE_PROBING, eth_addr_cmp, ETHADDR16_COPY, netif::hwaddr, ip_addr_cmp, IPADDR2_COPY, autoip::llipaddr, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, NULL, autoip::sent_num, and autoip::state.

Referenced by etharp_arp_input().

static err_t autoip_bind ( struct netif netif)
static

Configure interface for use with current LL IP-Address.

Parameters
netifnetwork interface to configure with current LL IP-Address

References netif::autoip, AUTOIP_DEBUG, ERR_OK, IP4_ADDR, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, autoip::llipaddr, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), netif_set_up(), netif::num, and U16_F.

Referenced by autoip_tmr().

static void autoip_create_addr ( struct netif netif,
ip_addr_t ipaddr 
)
static

Create an IP-Address out of range 169.254.1.0 to 169.254.254.255.

Parameters
netifnetwork interface on which create the IP-Address
ipaddrip address to initialize

References netif::autoip, AUTOIP_DEBUG, AUTOIP_NET, AUTOIP_RANGE_END, AUTOIP_RANGE_START, htonl, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, ip4_addr_set_u32, LWIP_ASSERT, LWIP_AUTOIP_CREATE_SEED_ADDR, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, autoip::tried_llipaddr, and U16_F.

Referenced by autoip_start().

static void autoip_handle_arp_conflict ( struct netif netif)
static
void autoip_network_changed ( struct netif netif)

Handle a possible change in the network configuration.

If there is an AutoIP address configured, take the interface down and begin probing with the same address.

References netif::autoip, autoip_start_probing(), AUTOIP_STATE_OFF, netif_set_down(), and autoip::state.

Referenced by netif_set_link_up().

static void autoip_restart ( struct netif netif)
static

Restart AutoIP client and check the next address (conflict detected)

Parameters
netifThe netif under AutoIP control

References netif::autoip, autoip_start(), and autoip::tried_llipaddr.

Referenced by autoip_arp_reply(), and autoip_handle_arp_conflict().

void autoip_set_struct ( struct netif netif,
struct autoip autoip 
)

Set a statically allocated struct autoip to work with.

Set a struct autoip allocated by the application to work with.

Using this prevents autoip_start to allocate it using mem_malloc.

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

References netif::autoip, LWIP_ASSERT, and NULL.

err_t autoip_stop ( struct netif netif)

Stop AutoIP client.

Parameters
netifnetwork interface on which stop the AutoIP client

References netif::autoip, AUTOIP_STATE_OFF, ERR_OK, netif_set_down(), and autoip::state.

Referenced by dhcp_bind(), dhcp_network_changed(), dhcp_stop(), and net_interface_down_imp().