dhcp_client.c File Reference

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

#include "core/net.h"
#include "dhcp/dhcp_client.h"
#include "dhcp/dhcp_common.h"
#include "dhcp/dhcp_debug.h"
#include "mdns/mdns_responder.h"
#include "date_time.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   DHCP_TRACE_LEVEL
 

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
 
const uint8_t dhcpOptionList []
 

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.

Description

The Dynamic Host Configuration Protocol is used to provide configuration parameters to hosts. Refer to the following RFCs for complete details:

  • RFC 2131: Dynamic Host Configuration Protocol
  • RFC 2132: DHCP Options and BOOTP Vendor Extensions
  • RFC 4039: Rapid Commit Option for the DHCP version 4
Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file dhcp_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   DHCP_TRACE_LEVEL

Definition at line 38 of file dhcp_client.c.

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.

◆ dhcpOptionList