WIZlib Library API  ver 1.0
WIZlib Library API User Menual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Enumerations | Functions

Dynamic Host Configuration Protocol. More...

Collaboration diagram for DHCP:


enum  dhcp_state {
 DHCP State. More...
 DHCP Action. More...


int8 dhcp_init (uint8 sock, void_func ip_update_hook, void_func ip_conflict_hook, wiz_NetInfo *def)
 Initialize DHCP module. More...
int8 dhcp_manual (dhcp_action action, uint32 *renew, uint32 *rebind)
 DHCP manual mode handler. More...
dhcp_state dhcp_get_state (void)
 Return current DHCP state. More...
void dhcp_set_storage (wiz_NetInfo *net)
 Update DHCP default address storage. More...
void dhcp_get_storage (wiz_NetInfo *net)
 Return DHCP default address storage. More...
void dhcp_static_mode (wiz_NetInfo *net)
 Change DHCP mode to Static. More...
void dhcp_auto_start (void)
 DHCP Auto mode (alarm mode) start function. More...

Detailed Description

Dynamic Host Configuration Protocol.

Enumeration Type Documentation

DHCP Action.


Do nothing (maybe previous DHCP action was failed)


Start IP Assign only when INIT state.


Start Renew only when BOUND state.


Start Rebind only when BOUND state.

Definition at line 38 of file dhcp.h.

enum dhcp_state

DHCP State.


INIT State - Send Discover Packet.


SEARCHING State - Waiting for Offer.


SELECTING State - Send Request.


REQUESTING State - Waiting for ACK.


IP_CHECK State - Check IP Validity.


BOUND State - Set Alarm for next step.


FAILED State - Set Static addresses temporally.

Definition at line 25 of file dhcp.h.

Function Documentation

void dhcp_auto_start ( void  )

DHCP Auto mode (alarm mode) start function.

  • Used for DHCP start action at Auto mode
    Auto mode can be selected at wizconfig.h file.
    (set USE_DHCP to VAL_ENABLE, and uncomment DHCP_AUTO define)
    and in the main loop, alarm_run should be called continuously.
  • At Static mode, it can be changed to DHCP mode through this function

Definition at line 404 of file dhcp.c.

dhcp_state dhcp_get_state ( void  )

Return current DHCP state.

DHCP state enum value (dhcp_state)

Definition at line 295 of file dhcp.c.

void dhcp_get_storage ( wiz_NetInfo net)

Return DHCP default address storage.

  • This may be different from real address device, because this is just default value.
  • MAC address of the storage is used when DHCP action (on the send packet)
  • The others are used when Static mode or DHCP failed
netThe struct variable in which storage addresses will be returned

Definition at line 342 of file dhcp.c.

int8 dhcp_init ( uint8  sock,
void_func  ip_update_hook,
void_func  ip_conflict_hook,
wiz_NetInfo def 

Initialize DHCP module.

This should be called just one time at first time

sockSocket number to use
ip_update_hookCallback function for IP-update hooking
ip_conflict_hookCallback function for IP-conflict hooking (Not implemented yet)
defDefault Address to set
RET_OK: Success
RET_NOK: Error

Definition at line 191 of file dhcp.c.

Here is the caller graph for this function:

int8 dhcp_manual ( dhcp_action  action,
uint32 *  renew,
uint32 *  rebind 

DHCP manual mode handler.

  • Blocking Function
  • Used only at DHCP manual mode (DHCP mode could be chosen at wizconfig.h file)
  • DHCP_MANUAL mode does not need a loop structure, but if there is no loop structure,
    you should handle renew & rebind with your own way, or just ignore renew & rebind action
actionThe action you want to do. (dhcp_action)
renewFor returning renew time when DHCP be bound (NULL will be ignored)
rebindFor returning rebind time when DHCP be bound (NULL will be ignored)
RET_OK: Success
RET_NOK: Error

Definition at line 234 of file dhcp.c.

void dhcp_set_storage ( wiz_NetInfo net)

Update DHCP default address storage.

You can update DHCP internal address storage through this

  • Normally, don't need to use this function except MAC address changed case
  • MAC address of the storage is used when DHCP action (on the send packet)
  • The others are used when Static mode or DHCP failed
netThe addresses you want to set at default address storage
  • All zero address (like or 0:0:0:0:0:0) will be ignored
    and be returned with address set formerly in it for reference
  • Member variable DHCP is not used (just ignored)
See Also
wiz_NetInfo, dhcp_get_storage
You should update MAC address when chip MAC address is changed.
If not, DHCP send packet will have wrong MAC address.

Definition at line 315 of file dhcp.c.

void dhcp_static_mode ( wiz_NetInfo net)

Change DHCP mode to Static.

Even though DHCP was enabled, it can be changed to Static mode through this function

netThe addresses you want to set as static addresses
  • NULL parameter or NULL member variable will be ignored and internal storage addresses will be used
    and these address will be returned in this net parameter (if not NULL)

Definition at line 364 of file dhcp.c.