DHCP Library

Top  Previous  Next

The DHCP library implements DHCP client on Ethernet (net.) and Wi-Fi (wln.) network interfaces. The DHCP protocol is used for automatic configuration of your device's IP address, netmask, and gateway IP address. More on the protocol here: http://en.wikipedia.org/wiki/Dhcp.

The library is capable of running DHCP clients on both network interfaces concurrently. The library is event-based and non-blocking — it quietly runs in the background and takes a minimal amount of CPU time.

Library Info

Supported platforms:

Any platform with at least the Ethernet (net.) or Wi-Fi (wln.) interface except for EM202.

Files to include:

Dhcp.tbs, dhcp.tbh (from current_library_set\dhcp\trunk\).


SOCK library;

You may also need WLN library

API procedures:

Use API procedures to interact with the library.

dhcp_get_info() — returns library-specific information (such as required buffer space).

dhcp_start() — starts the DHCP client on the specified network interface.

dhcp_stop() — stops the DHCP client on the specified network interface.

Event procedures:

Call event procedures from corresponding event handlers, as described here.

dhcp_proc_timer() — call this from the on_sys_timer() event handler.

dhcp_proc_data() — call this from the on_sock_data_arrival() event handler.

Callback procedures:

Implement the bodies of callback procedures elsewhere in your project.

callback_dhcp_ok() — called when the library completes successfully on one of the interfaces.

callback_dhcp_failure() — called when the library fails on one of the interfaces after DHCP_MAX_RETRIES.

callback_dhcp_pre_clear_ip() — called when the library is about to set the interface's IP to

callback_dchp_pre_buffrq() — called when the library needs to allocate buffer space and the required space is not available.

callback_dhcp_buff_released() — called when the library no longer needs buffers and released them.

Required buffer space:

6 buffer pages. These are utilized when needed and released when the DHCP client completes its job. The amount of buffer space needed is constant and does not depend on the number of network interfaces involved.