mikroSDK Reference Manual
dhcp_client.h
Go to the documentation of this file.
1
31#ifndef _DHCP_CLIENT_H
32#define _DHCP_CLIENT_H
33
34//Dependencies
35#include "core/net.h"
36#include "core/socket.h"
37#include "core/udp.h"
38#include "dhcp/dhcp_common.h"
39
40//DHCP client support
41#ifndef DHCP_CLIENT_SUPPORT
42 #define DHCP_CLIENT_SUPPORT ENABLED
43#elif (DHCP_CLIENT_SUPPORT != ENABLED && DHCP_CLIENT_SUPPORT != DISABLED)
44 #error DHCP_CLIENT_SUPPORT parameter is not valid
45#endif
46
47//DHCP client tick interval
48#ifndef DHCP_CLIENT_TICK_INTERVAL
49 #define DHCP_CLIENT_TICK_INTERVAL 200
50#elif (DHCP_CLIENT_TICK_INTERVAL < 10)
51 #error DHCP_CLIENT_TICK_INTERVAL parameter is not valid
52#endif
53
54//Random delay before sending the first message
55#ifndef DHCP_CLIENT_INIT_DELAY
56 #define DHCP_CLIENT_INIT_DELAY 2000
57#elif (DHCP_CLIENT_INIT_DELAY < 0)
58 #error DHCP_CLIENT_INIT_DELAY parameter is not valid
59#endif
60
61//Initial retransmission timeout (DHCPDISCOVER)
62#ifndef DHCP_CLIENT_DISCOVER_INIT_RT
63 #define DHCP_CLIENT_DISCOVER_INIT_RT 4000
64#elif (DHCP_CLIENT_DISCOVER_INIT_RT < 1000)
65 #error DHCP_CLIENT_DISCOVER_INIT_RT parameter is not valid
66#endif
67
68//Maximum retransmission timeout (DHCPDISCOVER)
69#ifndef DHCP_CLIENT_DISCOVER_MAX_RT
70 #define DHCP_CLIENT_DISCOVER_MAX_RT 16000
71#elif (DHCP_CLIENT_DISCOVER_MAX_RT < 1000)
72 #error DHCP_CLIENT_DISCOVER_MAX_RT parameter is not valid
73#endif
74
75//Maximum retransmission count (DHCPREQUEST)
76#ifndef DHCP_CLIENT_REQUEST_MAX_RC
77 #define DHCP_CLIENT_REQUEST_MAX_RC 4
78#elif (DHCP_CLIENT_REQUEST_MAX_RC < 1)
79 #error DHCP_CLIENT_REQUEST_MAX_RC parameter is not valid
80#endif
81
82//Initial retransmission timeout (DHCPREQUEST)
83#ifndef DHCP_CLIENT_REQUEST_INIT_RT
84 #define DHCP_CLIENT_REQUEST_INIT_RT 4000
85#elif (DHCP_CLIENT_REQUEST_INIT_RT < 1000)
86 #error DHCP_CLIENT_REQUEST_INIT_RT parameter is not valid
87#endif
88
89//Maximum retransmission timeout (DHCPREQUEST)
90#ifndef DHCP_CLIENT_REQUEST_MAX_RT
91 #define DHCP_CLIENT_REQUEST_MAX_RT 64000
92#elif (DHCP_CLIENT_REQUEST_MAX_RT < 1000)
93 #error DHCP_CLIENT_REQUEST_MAX_RT parameter is not valid
94#endif
95
96//Minimum delay between DHCPREQUEST messages in RENEWING and REBINDING states
97#ifndef DHCP_CLIENT_REQUEST_MIN_DELAY
98 #define DHCP_CLIENT_REQUEST_MIN_DELAY 60000
99#elif (DHCP_CLIENT_REQUEST_MIN_DELAY < 1000)
100 #error DHCP_CLIENT_REQUEST_MIN_DELAY parameter is not valid
101#endif
102
103//Number of probe packets
104#ifndef DHCP_CLIENT_PROBE_NUM
105 #define DHCP_CLIENT_PROBE_NUM 1
106#elif (DHCP_CLIENT_PROBE_NUM < 0)
107 #error DHCP_CLIENT_PROBE_NUM parameter is not valid
108#endif
109
110//Delay until repeated probe
111#ifndef DHCP_CLIENT_PROBE_DELAY
112 #define DHCP_CLIENT_PROBE_DELAY 1000
113#elif (DHCP_CLIENT_PROBE_DELAY < 100)
114 #error DHCP_CLIENT_PROBE_DELAY parameter is not valid
115#endif
116
117//Number of announcement packets
118#ifndef DHCP_CLIENT_ANNOUNCE_NUM
119 #define DHCP_CLIENT_ANNOUNCE_NUM 1
120#elif (DHCP_CLIENT_ANNOUNCE_NUM < 0)
121 #error DHCP_CLIENT_ANNOUNCE_NUM parameter is not valid
122#endif
123
124//Time between announcement packets
125#ifndef DHCP_CLIENT_ANNOUNCE_INTERVAL
126 #define DHCP_CLIENT_ANNOUNCE_INTERVAL 1000
127#elif (DHCP_CLIENT_ANNOUNCE_INTERVAL < 100)
128 #error DHCP_CLIENT_ANNOUNCE_INTERVAL parameter is not valid
129#endif
130
131//Random factor used to determine the delay between retransmissions
132#ifndef DHCP_CLIENT_RAND_FACTOR
133 #define DHCP_CLIENT_RAND_FACTOR 1000
134#elif (DHCP_CLIENT_RAND_FACTOR < 100)
135 #error DHCP_CLIENT_RAND_FACTOR parameter is not valid
136#endif
137
138//Application specific context
139#ifndef DHCP_CLIENT_PRIVATE_CONTEXT
140 #define DHCP_CLIENT_PRIVATE_CONTEXT
141#endif
142
143//Forward declaration of DhcpClientContext structure
144struct _DhcpClientContext;
145#define DhcpClientContext struct _DhcpClientContext
146
147//C++ guard
148#ifdef __cplusplus
149extern "C" {
150#endif
151
152
157typedef enum
158{
159 DHCP_STATE_INIT = 0,
160 DHCP_STATE_SELECTING = 1,
161 DHCP_STATE_REQUESTING = 2,
162 DHCP_STATE_INIT_REBOOT = 3,
163 DHCP_STATE_REBOOTING = 4,
164 DHCP_STATE_PROBING = 5,
165 DHCP_STATE_ANNOUNCING = 6,
166 DHCP_STATE_BOUND = 7,
167 DHCP_STATE_RENEWING = 8,
168 DHCP_STATE_REBINDING = 9
169} DhcpState;
170
171
176typedef void (*DhcpClientTimeoutCallback)(DhcpClientContext *context,
177 NetInterface *interface);
178
179
184typedef void (*DhcpClientLinkChangeCallback)(DhcpClientContext *context,
185 NetInterface *interface, bool_t linkState);
186
187
192typedef void (*DhcpClientStateChangeCallback)(DhcpClientContext *context,
193 NetInterface *interface, DhcpState state);
194
195
200typedef void (*DhcpClientAddOptionsCallback)(DhcpClientContext *context,
201 DhcpMessage *message, size_t *length, DhcpMessageType type);
202
203
208typedef error_t (*DhcpClientParseOptionsCallback)(DhcpClientContext *context,
209 const DhcpMessage *message, size_t length, DhcpMessageType type);
210
211
229
230
255
256
257//DHCP client related functions
258void dhcpClientGetDefaultSettings(DhcpClientSettings *settings);
259
260error_t dhcpClientInit(DhcpClientContext *context,
261 const DhcpClientSettings *settings);
262
263error_t dhcpClientStart(DhcpClientContext *context);
264error_t dhcpClientStop(DhcpClientContext *context);
265
266error_t dhcpClientRelease(DhcpClientContext *context);
267DhcpState dhcpClientGetState(DhcpClientContext *context);
268
269//C++ guard
270#ifdef __cplusplus
271}
272#endif
273
274#endif
void(* DhcpClientTimeoutCallback)(DhcpClientContext *context, NetInterface *interface)
DHCP configuration timeout callback.
Definition dhcp_client.h:176
error_t(* DhcpClientParseOptionsCallback)(DhcpClientContext *context, const DhcpMessage *message, size_t length, DhcpMessageType type)
Parse DHCP options callback.
Definition dhcp_client.h:208
void(* DhcpClientAddOptionsCallback)(DhcpClientContext *context, DhcpMessage *message, size_t *length, DhcpMessageType type)
Add DHCP options callback.
Definition dhcp_client.h:200
DhcpState
DHCP FSM states.
Definition dhcp_client.h:158
void(* DhcpClientLinkChangeCallback)(DhcpClientContext *context, NetInterface *interface, bool_t linkState)
Link state change callback.
Definition dhcp_client.h:184
void(* DhcpClientStateChangeCallback)(DhcpClientContext *context, NetInterface *interface, DhcpState state)
FSM state change callback.
Definition dhcp_client.h:192
Definitions common to DHCP client and server.
DhcpMessageType
DHCP message types.
Definition dhcp_common.h:88
error_t
Error codes.
Definition error.h:43
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
Socket API.
DHCP client settings.
Definition dhcp_client.h:217
DhcpClientAddOptionsCallback addOptionsCallback
Add DHCP options callback.
Definition dhcp_client.h:226
DhcpClientStateChangeCallback stateChangeEvent
FSM state change event.
Definition dhcp_client.h:225
bool_t manualDnsConfig
Force manual DNS configuration.
Definition dhcp_client.h:221
DhcpClientTimeoutCallback timeoutEvent
DHCP configuration timeout event.
Definition dhcp_client.h:223
DhcpClientLinkChangeCallback linkChangeEvent
Link state change event.
Definition dhcp_client.h:224
systime_t timeout
DHCP configuration timeout.
Definition dhcp_client.h:222
NetInterface * interface
Network interface to configure.
Definition dhcp_client.h:218
bool_t rapidCommit
Quick configuration using rapid commit.
Definition dhcp_client.h:220
uint_t ipAddrIndex
Index of the IP address to be configured.
Definition dhcp_client.h:219
DhcpClientParseOptionsCallback parseOptionsCallback
Parse DHCP options callback.
Definition dhcp_client.h:227
DHCP client context.
Definition dhcp_client.h:236
Ipv4Addr serverIpAddr
DHCP server IPv4 address.
Definition dhcp_client.h:245
Ipv4Addr requestedIpAddr
Requested IPv4 address.
Definition dhcp_client.h:246
systime_t configStartTime
Address acquisition or renewal process start time.
Definition dhcp_client.h:248
uint32_t leaseTime
Lease time.
Definition dhcp_client.h:250
systime_t retransmitTimeout
Retransmission timeout.
Definition dhcp_client.h:243
bool_t running
This flag tells whether the DHCP client is running or not.
Definition dhcp_client.h:238
uint32_t t2
Time at which the client enters the REBINDING state.
Definition dhcp_client.h:252
DhcpState state
Current state of the FSM.
Definition dhcp_client.h:239
uint32_t t1
Time at which the client enters the RENEWING state.
Definition dhcp_client.h:251
uint32_t transactionId
Value to match requests with replies.
Definition dhcp_client.h:247
uint_t retransmitCount
Retransmission counter.
Definition dhcp_client.h:244
bool_t timeoutEventDone
Timeout callback function has been called.
Definition dhcp_client.h:240
DhcpClientSettings settings
DHCP client settings.
Definition dhcp_client.h:237
systime_t timestamp
Timestamp to manage retransmissions.
Definition dhcp_client.h:241
systime_t leaseStartTime
Lease start time.
Definition dhcp_client.h:249
systime_t timeout
Timeout value.
Definition dhcp_client.h:242
UDP (User Datagram Protocol)