NetBurner 3.5.6
PDF Version
dhcpclient.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
29#ifndef _NB_DHCP_CLIENT_H
30#define _NB_DHCP_CLIENT_H
31
32#include <buffers.h>
33#include <nbrtos.h>
34#include <nettimer.h>
35#include <nettypes.h>
36
37// Functions necessary to use DHCP in the simplest form
38#define DHCP_OK (0)
39#define DHCP_NOTNEEDED (1)
40#define DHCP_FALLBACK (2)
41#define DHCP_FAILED (-1)
42
43#define DHCP_LINK_DOWN_RESTART_TICKS (5 * TICKS_PER_SECOND)
44
48#define SDHCP_NOTSTARTED 0
49#define SDHCP_DISCOVER 1
50#define SDHCP_OFFER 2
51#define SDHCP_ACK 3
52#define SDHCP_INIT 4
53#define SDHCP_CMPL 5
54#define SDHCP_RENEW 6
55#define SDHCP_REBIND 7
56#define SDHCP_RELEASE 8
57#define SBOOTP_TRANSMITTING 9
58#define SBOOTP_DONE 10
59#define SDHCP_FAILED 11
62class InterfaceBlock; // Forward declaration
63class DHCPMessage; // Forward declaration
64
70class DhcpObject : public TimeOutElement
71{
72 private:
73 int DhcpState; // Current state of DHCP engine
74 int DhcpRetryCount; // Number of transmit retries.
75 int DhcpTimeCounter; // Number of seconds til retry
76 uint32_t DHCPLastXid; // Last XID
77 int DhcpBackoffTimer;
78 volatile int DhcpPendingPacket;
79 uint32_t DhcpLeasePendingStart; // IP address lease start time in seconds
80 uint32_t DhcpLeaseDuration; // Relative duration of lease in seconds
81
82 void CreateDhcpRenewMsg(DHCPMessage &NewMsg);
83 void CreateDhcpReleaseMsg(DHCPMessage &NewMsg);
84 BOOLEAN BootpConfig(DHCPMessage &Msg);
85 BOOLEAN DhcpConfig(DHCPMessage &Msg);
86 void UpdateIPRuntimeVars(BOOLEAN release);
87 void ReTransmitPacket(uint32_t xid = 0);
88 void CreateBootpMsg(DHCPMessage &NewMsg);
89 uint32_t GetNextEventIntervalSecs();
90
91 BOOL bProcessThisDhcp;
92 DhcpObject *m_next_in_list;
93 uint32_t m_LinkChangeTick;
94
95 virtual void TimeElementEvent();
96
97 public:
98 IPADDR4 DhcpClientIP; // Allocated IP address
99 IPADDR4 DhcpClientMask; // Allocated subnet mask
100 IPADDR4 DhcpServerIP; // Server ID
101 IPADDR4 DhcpRelayIP; // Relay Agent
102 IPADDR4 DhcpRouterIP; // Gateway IP
103 IPADDR4 DhcpDNSIP; // DNS IP
104 IPADDR4 DhcpDNSIP2; // 2nd DNS IP
105 uint32_t DhcpLeaseStart; // IP address lease start time in seconds
106 uint32_t DhcpLeaseTime; // IP address lease time in seconds
107 uint32_t DhcpRenewTime; // Time to Renewing state in seconds
108 uint32_t DhcpRebindTime; // Time to Rebinding state in seconds
109 InterfaceBlock *pIfb; // Interface to use
110 OS_SEM NotifySem;
111
124 void StartDHCP();
125
126 // Start the BOOTP process
127 void StartBOOTP();
128
129 // After BOOTP has failed call this to stop BOOTP processing
130 void StopBOOTP();
131
141 void StopDHCP();
142
153
167
177 void RenewDHCP();
178
189
199
209
218 uint32_t GetDhcpRenewTime() { return DhcpRenewTime; }
219
228 uint32_t GetDhcpRebindTime() { return DhcpRebindTime; }
229
238 uint32_t GetDhcpExpirationTime() { return DhcpLeaseTime; }
239
248 int32_t GetDHCPState();
249
250 //---- function prototypes -----
251 void PrintDhcpState(int state);
252
253 void DHCPTimer();
254 void DHCPPacket(PoolPtr p);
255
256 static void staticDHCPPacket(PoolPtr p);
257
258 void StopProcessing();
259
261 ~DhcpObject();
262
263 void (*leaseExpiredCallback)(DhcpObject *dhcpClient);
264 void (*DHCPFailedCallback)(DhcpObject *dhcpClient);
265 void (*leaseObtainedCallback)(DhcpObject *dhcpClient);
266
267 void LinkNotify(bool link);
268
269 friend void PrintDhcpStatus(DhcpObject &dob);
270 friend void PrintDhcpState(int state);
271
272}; // End of DHCP Object
273
286int32_t GetIntefaceDHCPState(int interface = 0);
287
301int32_t WaitForDHCPInterface(int interface = 0, uint16_t TicksToWait = 10 * TICKS_PER_SECOND);
302
303#endif
DHCP client class.
Definition dhcpclient.h:71
uint32_t GetDhcpRenewTime()
Returns number of seconds remaining before the lease will be renewed.
Definition dhcpclient.h:218
uint32_t GetRemainingDhcpLeaseTime()
Returns number of seconds remaining for current lease.
bool bDoFallBack()
Returns true if a DHCP fallback event has occurred.
void RebindDHCP()
Manually force a DHCP rebind of a lease.
BOOL ValidDhcpLease()
Returns the status of a DHCP lease.
void RestartDHCP()
Manually stop are resetart the DHCP client.
void StopDHCP()
Manually stop the DHCP client and release the DHCP lease.
uint32_t GetDhcpRebindTime()
Returns number of seconds remaining before the current lease will have to rebind.
Definition dhcpclient.h:228
int32_t GetDHCPState()
Returns current state of the DHCP lease.
uint32_t GetDhcpExpirationTime()
Returns number of seconds remaining before the current lease will expire.
Definition dhcpclient.h:238
void StartDHCP()
Manually start the DHCP Client.
void RenewDHCP()
Manually force a DHCP renew of a lease.
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:245
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
int32_t GetIntefaceDHCPState(int interface=0)
Returns current state of the DHCP lease, with optional interface parameter.
int32_t WaitForDHCPInterface(int interface=0, uint16_t TicksToWait=10 *TICKS_PER_SECOND)
Wait until a DHCP lease is obtained, or the timeout occurs.
Main buffer structure for network and serial communication.
Definition buffers.h:90