dhcp_client.h File Reference

DHCP client (Dynamic Host Configuration Protocol) More...

#include "core/net.h"
#include "core/socket.h"
#include "core/udp.h"
#include "dhcp/dhcp_common.h"

Go to the source code of this file.

Data Structures

struct  DhcpClientSettings
 DHCP client settings. More...
 
struct  _DhcpClientContext
 DHCP client context. More...
 

Macros

#define DHCP_CLIENT_SUPPORT   ENABLED
 
#define DHCP_CLIENT_TICK_INTERVAL   200
 
#define DHCP_CLIENT_HOSTNAME_OPTION_SUPPORT   ENABLED
 
#define DHCP_CLIENT_MAX_HOSTNAME_LEN   15
 
#define DHCP_CLIENT_ID_OPTION_SUPPORT   DISABLED
 
#define DHCP_CLIENT_MAX_ID_SIZE   15
 
#define DHCP_CLIENT_INIT_DELAY   2000
 
#define DHCP_CLIENT_DISCOVER_INIT_RT   4000
 
#define DHCP_CLIENT_DISCOVER_MAX_RT   16000
 
#define DHCP_CLIENT_REQUEST_MAX_RC   4
 
#define DHCP_CLIENT_REQUEST_INIT_RT   4000
 
#define DHCP_CLIENT_REQUEST_MAX_RT   64000
 
#define DHCP_CLIENT_REQUEST_MIN_DELAY   60000
 
#define DHCP_CLIENT_PROBE_NUM   1
 
#define DHCP_CLIENT_PROBE_DELAY   1000
 
#define DHCP_CLIENT_RAND_FACTOR   1000
 
#define DhcpClientContext   struct _DhcpClientContext
 

Typedefs

typedef void(* DhcpTimeoutCallback) (DhcpClientContext *context, NetInterface *interface)
 DHCP configuration timeout callback. More...
 
typedef void(* DhcpLinkChangeCallback) (DhcpClientContext *context, NetInterface *interface, bool_t linkState)
 Link state change callback. More...
 
typedef void(* DhcpStateChangeCallback) (DhcpClientContext *context, NetInterface *interface, DhcpState state)
 FSM state change callback. More...
 

Enumerations

enum  DhcpState {
  DHCP_STATE_INIT = 0, DHCP_STATE_SELECTING = 1, DHCP_STATE_REQUESTING = 2, DHCP_STATE_INIT_REBOOT = 3,
  DHCP_STATE_REBOOTING = 4, DHCP_STATE_PROBING = 5, DHCP_STATE_BOUND = 6, DHCP_STATE_RENEWING = 7,
  DHCP_STATE_REBINDING = 8
}
 DHCP FSM states. More...
 

Functions

void dhcpClientGetDefaultSettings (DhcpClientSettings *settings)
 Initialize settings with default values. More...
 
error_t dhcpClientInit (DhcpClientContext *context, const DhcpClientSettings *settings)
 DHCP client initialization. More...
 
error_t dhcpClientStart (DhcpClientContext *context)
 Start DHCP client. More...
 
error_t dhcpClientStop (DhcpClientContext *context)
 Stop DHCP client. More...
 
DhcpState dhcpClientGetState (DhcpClientContext *context)
 Retrieve current state. More...
 
void dhcpClientTick (DhcpClientContext *context)
 DHCP client timer handler. More...
 
void dhcpClientLinkChangeEvent (DhcpClientContext *context)
 Callback function for link change event. More...
 
void dhcpClientStateInit (DhcpClientContext *context)
 INIT state. More...
 
void dhcpClientStateSelecting (DhcpClientContext *context)
 SELECTING state. More...
 
void dhcpClientStateRequesting (DhcpClientContext *context)
 REQUESTING state. More...
 
void dhcpClientStateInitReboot (DhcpClientContext *context)
 INIT-REBOOT state. More...
 
void dhcpClientStateRebooting (DhcpClientContext *context)
 REBOOTING state. More...
 
void dhcpClientStateProbing (DhcpClientContext *context)
 PROBING state. More...
 
void dhcpClientStateBound (DhcpClientContext *context)
 BOUND state. More...
 
void dhcpClientStateRenewing (DhcpClientContext *context)
 RENEWING state. More...
 
void dhcpClientStateRebinding (DhcpClientContext *context)
 REBINDING state. More...
 
error_t dhcpClientSendDiscover (DhcpClientContext *context)
 Send DHCPDISCOVER message. More...
 
error_t dhcpClientSendRequest (DhcpClientContext *context)
 Send DHCPREQUEST message. More...
 
error_t dhcpClientSendDecline (DhcpClientContext *context)
 Send DHCPDECLINE message. More...
 
void dhcpClientProcessMessage (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param)
 Process incoming DHCP message. More...
 
void dhcpClientParseOffer (DhcpClientContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPOFFER message. More...
 
void dhcpClientParseAck (DhcpClientContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPACK message. More...
 
void dhcpClientParseNak (DhcpClientContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPNAK message. More...
 
void dhcpClientCheckTimeout (DhcpClientContext *context)
 Manage DHCP configuration timeout. More...
 
uint16_t dhcpClientComputeElapsedTime (DhcpClientContext *context)
 Compute the appropriate secs field. More...
 
void dhcpClientChangeState (DhcpClientContext *context, DhcpState newState, systime_t delay)
 Update DHCP FSM state. More...
 
void dhcpClientDumpConfig (DhcpClientContext *context)
 Dump DHCP configuration for debugging purpose. More...
 

Variables

systime_t dhcpClientTickCounter
 

Detailed Description

DHCP client (Dynamic Host Configuration Protocol)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file dhcp_client.h.

Macro Definition Documentation

◆ DHCP_CLIENT_DISCOVER_INIT_RT

#define DHCP_CLIENT_DISCOVER_INIT_RT   4000

Definition at line 89 of file dhcp_client.h.

◆ DHCP_CLIENT_DISCOVER_MAX_RT

#define DHCP_CLIENT_DISCOVER_MAX_RT   16000

Definition at line 96 of file dhcp_client.h.

◆ DHCP_CLIENT_HOSTNAME_OPTION_SUPPORT

#define DHCP_CLIENT_HOSTNAME_OPTION_SUPPORT   ENABLED

Definition at line 54 of file dhcp_client.h.

◆ DHCP_CLIENT_ID_OPTION_SUPPORT

#define DHCP_CLIENT_ID_OPTION_SUPPORT   DISABLED

Definition at line 68 of file dhcp_client.h.

◆ DHCP_CLIENT_INIT_DELAY

#define DHCP_CLIENT_INIT_DELAY   2000

Definition at line 82 of file dhcp_client.h.

◆ DHCP_CLIENT_MAX_HOSTNAME_LEN

#define DHCP_CLIENT_MAX_HOSTNAME_LEN   15

Definition at line 61 of file dhcp_client.h.

◆ DHCP_CLIENT_MAX_ID_SIZE

#define DHCP_CLIENT_MAX_ID_SIZE   15

Definition at line 75 of file dhcp_client.h.

◆ DHCP_CLIENT_PROBE_DELAY

#define DHCP_CLIENT_PROBE_DELAY   1000

Definition at line 138 of file dhcp_client.h.

◆ DHCP_CLIENT_PROBE_NUM

#define DHCP_CLIENT_PROBE_NUM   1

Definition at line 131 of file dhcp_client.h.

◆ DHCP_CLIENT_RAND_FACTOR

#define DHCP_CLIENT_RAND_FACTOR   1000

Definition at line 145 of file dhcp_client.h.

◆ DHCP_CLIENT_REQUEST_INIT_RT

#define DHCP_CLIENT_REQUEST_INIT_RT   4000

Definition at line 110 of file dhcp_client.h.

◆ DHCP_CLIENT_REQUEST_MAX_RC

#define DHCP_CLIENT_REQUEST_MAX_RC   4

Definition at line 103 of file dhcp_client.h.

◆ DHCP_CLIENT_REQUEST_MAX_RT

#define DHCP_CLIENT_REQUEST_MAX_RT   64000

Definition at line 117 of file dhcp_client.h.

◆ DHCP_CLIENT_REQUEST_MIN_DELAY

#define DHCP_CLIENT_REQUEST_MIN_DELAY   60000

Definition at line 124 of file dhcp_client.h.

◆ DHCP_CLIENT_SUPPORT

#define DHCP_CLIENT_SUPPORT   ENABLED

Definition at line 40 of file dhcp_client.h.

◆ DHCP_CLIENT_TICK_INTERVAL

#define DHCP_CLIENT_TICK_INTERVAL   200

Definition at line 47 of file dhcp_client.h.

◆ DhcpClientContext

#define DhcpClientContext   struct _DhcpClientContext

Definition at line 152 of file dhcp_client.h.

Typedef Documentation

◆ DhcpLinkChangeCallback

typedef void(* DhcpLinkChangeCallback) (DhcpClientContext *context, NetInterface *interface, bool_t linkState)

Link state change callback.

Definition at line 190 of file dhcp_client.h.

◆ DhcpStateChangeCallback

typedef void(* DhcpStateChangeCallback) (DhcpClientContext *context, NetInterface *interface, DhcpState state)

FSM state change callback.

Definition at line 198 of file dhcp_client.h.

◆ DhcpTimeoutCallback

typedef void(* DhcpTimeoutCallback) (DhcpClientContext *context, NetInterface *interface)

DHCP configuration timeout callback.

Definition at line 182 of file dhcp_client.h.

Enumeration Type Documentation

◆ DhcpState

enum DhcpState

DHCP FSM states.

Enumerator
DHCP_STATE_INIT 
DHCP_STATE_SELECTING 
DHCP_STATE_REQUESTING 
DHCP_STATE_INIT_REBOOT 
DHCP_STATE_REBOOTING 
DHCP_STATE_PROBING 
DHCP_STATE_BOUND 
DHCP_STATE_RENEWING 
DHCP_STATE_REBINDING 

Definition at line 164 of file dhcp_client.h.

Function Documentation

◆ dhcpClientChangeState()

void dhcpClientChangeState ( DhcpClientContext context,
DhcpState  newState,
systime_t  delay 
)

Update DHCP FSM state.

Parameters
[in]contextPointer to the DHCP client context
[in]newStateNew DHCP state to switch to
[in]delayInitial delay

Definition at line 1809 of file dhcp_client.c.

◆ dhcpClientCheckTimeout()

void dhcpClientCheckTimeout ( DhcpClientContext context)

Manage DHCP configuration timeout.

Parameters
[in]contextPointer to the DHCP client context

Definition at line 1741 of file dhcp_client.c.

◆ dhcpClientComputeElapsedTime()

uint16_t dhcpClientComputeElapsedTime ( DhcpClientContext context)

Compute the appropriate secs field.

Compute the number of seconds elapsed since the client began address acquisition or renewal process

Parameters
[in]contextPointer to the DHCP client context
Returns
The elapsed time expressed in seconds

Definition at line 1786 of file dhcp_client.c.

◆ dhcpClientDumpConfig()

void dhcpClientDumpConfig ( DhcpClientContext context)

Dump DHCP configuration for debugging purpose.

Parameters
[in]contextPointer to the DHCP client context

Definition at line 1873 of file dhcp_client.c.

◆ dhcpClientGetDefaultSettings()

void dhcpClientGetDefaultSettings ( DhcpClientSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains DHCP client settings

Definition at line 73 of file dhcp_client.c.

◆ dhcpClientGetState()

DhcpState dhcpClientGetState ( DhcpClientContext context)

Retrieve current state.

Parameters
[in]contextPointer to the DHCP client context
Returns
Current DHCP client state

Definition at line 251 of file dhcp_client.c.

◆ dhcpClientInit()

error_t dhcpClientInit ( DhcpClientContext context,
const DhcpClientSettings settings 
)

DHCP client initialization.

Parameters
[in]contextPointer to the DHCP client context
[in]settingsDHCP client specific settings
Returns
Error code

Definition at line 110 of file dhcp_client.c.

◆ dhcpClientLinkChangeEvent()

void dhcpClientLinkChangeEvent ( DhcpClientContext context)

Callback function for link change event.

Parameters
[in]contextPointer to the DHCP client context

Definition at line 354 of file dhcp_client.c.

◆ dhcpClientParseAck()

void dhcpClientParseAck ( DhcpClientContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPACK message.

Parameters
[in]contextPointer to the DHCP client context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse
Returns
Error code

Definition at line 1445 of file dhcp_client.c.

◆ dhcpClientParseNak()

void dhcpClientParseNak ( DhcpClientContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPNAK message.

Parameters
[in]contextPointer to the DHCP client context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse
Returns
Error code

Definition at line 1673 of file dhcp_client.c.

◆ dhcpClientParseOffer()

void dhcpClientParseOffer ( DhcpClientContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPOFFER message.

Parameters
[in]contextPointer to the DHCP client context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 1392 of file dhcp_client.c.

◆ dhcpClientProcessMessage()

void dhcpClientProcessMessage ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const UdpHeader udpHeader,
const NetBuffer buffer,
size_t  offset,
void *  param 
)

Process incoming DHCP message.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderUDP pseudo header
[in]udpHeaderUDP header
[in]bufferMulti-part buffer containing the incoming DHCP message
[in]offsetOffset to the first byte of the DHCP message
[in]paramPointer to the DHCP client context

Definition at line 1309 of file dhcp_client.c.

◆ dhcpClientSendDecline()

error_t dhcpClientSendDecline ( DhcpClientContext context)

Send DHCPDECLINE message.

Parameters
[in]contextPointer to the DHCP client context
Returns
Error code

Definition at line 1222 of file dhcp_client.c.

◆ dhcpClientSendDiscover()

error_t dhcpClientSendDiscover ( DhcpClientContext context)

Send DHCPDISCOVER message.

Parameters
[in]contextPointer to the DHCP client context
Returns
Error code

Definition at line 965 of file dhcp_client.c.

◆ dhcpClientSendRequest()

error_t dhcpClientSendRequest ( DhcpClientContext context)

Send DHCPREQUEST message.

Parameters
[in]contextPointer to the DHCP client context
Returns
Error code

Definition at line 1076 of file dhcp_client.c.

◆ dhcpClientStart()

error_t dhcpClientStart ( DhcpClientContext context)

Start DHCP client.

Parameters
[in]contextPointer to the DHCP client context
Returns
Error code

Definition at line 177 of file dhcp_client.c.

◆ dhcpClientStateBound()

void dhcpClientStateBound ( DhcpClientContext context)

BOUND state.

Client has a valid lease and is in its normal operating state

Parameters
[in]contextPointer to the DHCP client context

Definition at line 782 of file dhcp_client.c.

◆ dhcpClientStateInit()

void dhcpClientStateInit ( DhcpClientContext context)

INIT state.

This is the initialization state, where a client begins the process of acquiring a lease. It also returns here when a lease ends, or when a lease negotiation fails

Parameters
[in]contextPointer to the DHCP client context

Definition at line 416 of file dhcp_client.c.

◆ dhcpClientStateInitReboot()

void dhcpClientStateInitReboot ( DhcpClientContext context)

INIT-REBOOT state.

When a client that already has a valid lease starts up after a power-down or reboot, it starts here instead of the INIT state

Parameters
[in]contextPointer to the DHCP client context

Definition at line 597 of file dhcp_client.c.

◆ dhcpClientStateProbing()

void dhcpClientStateProbing ( DhcpClientContext context)

PROBING state.

The client probes the newly received address

Parameters
[in]contextPointer to the DHCP client context

Definition at line 715 of file dhcp_client.c.

◆ dhcpClientStateRebinding()

void dhcpClientStateRebinding ( DhcpClientContext context)

REBINDING state.

The client has failed to renew its lease with the server that originally granted it, and now seeks a lease extension with any server that can hear it. It periodically sends DHCPREQUEST messages with no server specified until it gets a reply or the lease ends

Parameters
[in]contextPointer to the DHCP client context

Definition at line 888 of file dhcp_client.c.

◆ dhcpClientStateRebooting()

void dhcpClientStateRebooting ( DhcpClientContext context)

REBOOTING state.

A client that has rebooted with an assigned address is waiting for a confirming reply from a server

Parameters
[in]contextPointer to the DHCP client context

Definition at line 637 of file dhcp_client.c.

◆ dhcpClientStateRenewing()

void dhcpClientStateRenewing ( DhcpClientContext context)

RENEWING state.

Client is trying to renew its lease. It regularly sends DHCPREQUEST messages with the server that gave it its current lease specified, and waits for a reply

Parameters
[in]contextPointer to the DHCP client context

Definition at line 823 of file dhcp_client.c.

◆ dhcpClientStateRequesting()

void dhcpClientStateRequesting ( DhcpClientContext context)

REQUESTING state.

The client is waiting to hear back from the server to which it sent its request

Parameters
[in]contextPointer to the DHCP client context

Definition at line 518 of file dhcp_client.c.

◆ dhcpClientStateSelecting()

void dhcpClientStateSelecting ( DhcpClientContext context)

SELECTING state.

The client is waiting to receive DHCPOFFER messages from one or more DHCP servers, so it can choose one

Parameters
[in]contextPointer to the DHCP client context

Definition at line 456 of file dhcp_client.c.

◆ dhcpClientStop()

error_t dhcpClientStop ( DhcpClientContext context)

Stop DHCP client.

Parameters
[in]contextPointer to the DHCP client context
Returns
Error code

Definition at line 220 of file dhcp_client.c.

◆ dhcpClientTick()

void dhcpClientTick ( DhcpClientContext context)

DHCP client timer handler.

This routine must be periodically called by the TCP/IP stack to manage DHCP client operation

Parameters
[in]contextPointer to the DHCP client context

Definition at line 277 of file dhcp_client.c.

Variable Documentation

◆ dhcpClientTickCounter

systime_t dhcpClientTickCounter

Definition at line 53 of file dhcp_client.c.