API Reference Manual  r8305
Network address functions

Functions

void wlp_set_ipaddr_cb (void(*addr_cb)(void *ctx, const struct ip_addr *addr), void *ctx)
 Register a callback that will be invoked when an IP address is set.
int wlp_set_ipaddr (const struct ip_addr *ip, const struct ip_addr *netmask, const struct ip_addr *gw, const struct ip_addr *dns)
 Set a static IP address.
int wlp_get_ipaddr (struct ip_addr *ip, struct ip_addr *netmask, struct ip_addr *gw, struct ip_addr *dns)
 Get the current IP address parameters.
int wlp_set_dhcp (int enable)
 Request or release IP address through DHCP.
int wlp_get_dhcp (int *enabled)
 Get the current DHCP configuration.
int wlp_set_dhcpd (int enable)
 Start or stop the device DHCP server.

Detailed Description

These functions manage the network address configuration.


Function Documentation

int wlp_get_dhcp ( int *  enabled)

Get the current DHCP configuration.

Get information on whether DHCP is enabled or not. Note that wlp_get_dhcp() will not indicate whether an actual IP address has been obtained through DHCP or not. See wlp_set_ipaddr_cb() for information about IP address notifications.

Parameters:
enabledwill hold the DHCP configuration upon successful return. Not used if NULL.
Returns:
  • 0 on success
  • WLP_ERR_CONN if not connected (DHCP configuration will still be filled in into the provided parameter).
int wlp_get_ipaddr ( struct ip_addr ip,
struct ip_addr netmask,
struct ip_addr gw,
struct ip_addr dns 
)

Get the current IP address parameters.

The currently assigned IP address setttings for the wifi device will be fetched. If DHCP is enabled (through wlp_set_dhcp()) and the IP configuration has not yet been assigned, all IP address values will be IP_ADDR_ANY. If DHCP is disabled the statically assigned IP addresses will be fetched.

Parameters:
ipwill hold the current IP address upon successful return. Not used if NULL.
netmaskwill hold the current netmask upon successful return. Not used if NULL.
gwwill hold the current default gateway address upon successful return. Not used if NULL.
dnswill hold the current dns server address upon successful return. return. Not used if NULL.
Returns:
  • 0 on success
  • WLP_ERR_CONN if not connected (IP address configuration will still be filled in into the provided parameters).
int wlp_set_dhcp ( int  enable)

Request or release IP address through DHCP.

Enable or disable DHCP for IP address configuration. If this function is called when the wifi link is up, an IP address will be requested or released upon successful return, depending on the value of the enable parameter. See wlp_set_ipaddr_cb() on how to get notified when the IP address configuration is set or removed.

wlp_set_dhcp() can be invoked either before or after the wifi link is up. If this function is called when the wifi link is down, any DHCP requests will be performed when the wifi link comes up.

If DHCP is enabled through this function, any configuration set through wl_set_ipaddr() will not be used.

Note that the current IP address settings can be obtained through wl_get_ipaddr() at any time.

Parameters:
enabledetermines if DHCP should be enabled or disabled.
Returns:
0 on success.
int wlp_set_dhcpd ( int  enable)

Start or stop the device DHCP server.

Enable or disable DHCP server for IP address configuration.

wlp_set_dhcpd() can be invoked either before or after the wifi link is up. If this function is called when the wifi link is down, any DHCP services will be performed when the wifi link comes up.

Technically, it is possible to enable the DHCP server in STA mode or AP mode. However, it seldom makes sense to use a DHCP server in STA mode.

The DHCP server will offer IP addresses in the range x.y.z.100 to x.y.z.255. For instance; if the ip address of the device is 192.168.1.1 and netmask 255.255.255.0 is used, the DHCP server will offer IP addresses in the range 192.168.1.100 to 192.168.1.255. If the netmask was 255.255.0.0 the range would be the same. In case the netmask is something like 255.255.255.y, where y != 0, we would mask out the some of the IP addresses in the above range to make sure that all offered IP addresses are actually valid on the given network.

When using the DHCP server, a static IP address must be assigned to the device. The gateway address that is set with wlp_set_ipaddr() will be used as the address in the "router" DHCP option. Some systems (notably IOS devices) will not bring the link up completely unless this option is a valid address so it is usually wise to set the gateway address to the same static IP address that is used for the DHCP Server itself (unless you know that it should be set to something particular).

Parameters:
enabledetermines if the DHCP server should be enabled or disabled.
Returns:
  • 0 on success.
int wlp_set_ipaddr ( const struct ip_addr ip,
const struct ip_addr netmask,
const struct ip_addr gw,
const struct ip_addr dns 
)

Set a static IP address.

Disable DHCP and configure the device static IP address settings. wlp_set_ipaddr() can be invoked either before or after the wifi link is up.

If a static IP address is configured using this function, any callback registered with wlp_set_ipaddr_cb() will be invoked as soon as the wifi link status changes (see wlp_linkup()).

Parameters:
ipis the IP address to set, e.g. 192.168.1.100. Not used if NULL.
maskis the network mask, e.g. 255.255.255.0. Not used if NULL.
gwis the gateway to use, e.g. 192.168.1.1. Not used if NULL.
dnsis the dns server to use, e.g. 192.168.1.1. Not used if NULL.
Returns:
  • 0 on success.
void wlp_set_ipaddr_cb ( void(*)(void *ctx, const struct ip_addr *addr)  addr_cb,
void *  ctx 
)

Register a callback that will be invoked when an IP address is set.

The provided callback will be invoked when an IP address is set or removed. Every time wlp_poll() is invoked, the callback condition will be evaluated and any registered callback will be invoked from same context as the call to wlp_poll().

If a static IP address is configured (through wlp_set_ipaddr()), this function will be called at the same time as the link callback registered in wlp_set_link_cb().

If a dynamic IP address is configured (through wlp_set_dhcp()) this function will be called when the link is up and an address has been successfully obatined through DHCP. It will also be called when the wifi link goes down (since the IP address will be removed at that time) or if the IP address is relesed through a call to set_dhcp() with argument 0.

Note that the connection status will also be indicated by any wlp_api that performs socket communication (e.g. wlp_send() and wlp_recv()) through their return values, even though wlp_set_ipaddr_cb() has not been called.

Parameters:
addr_cbis called when the IP address is set or removed. If the address is set, the current address will be provided in the addr parameter. If the address is removed, the addr parameter will be NULL.
ctxis an opaque context parameter that will be passed back to the addr_cb.