/* flaneth - flash and ethernet - dartboard mod
* version 0.1 date 2008-11-09
* Copyright (C) 2007-2008 Stefan Schuermans <stefan@schuermans.info>
* Copyleft: GNU public license V2 - http://www.gnu.org/copyleft/gpl.html
* a BlinkenArea project - http://www.blinkenarea.org/
*/
#include <string.h>
#include "config.h"
#include "checksum.h"
#include "debug.h"
#include "dhcp.h"
#include "ethernet.h"
#include "ip.h"
#include "macros.h"
#include "nethelp.h"
#include "random.h"
#include "udp.h"
// configuration
static const unsigned char DhcpRetrySecsMax = 10; // avarage timeout after which to retry DHCP action
static const unsigned char DhcpRetriesMax = 5; // maximum number of retries before aborting DHCP action
static const unsigned long DhcpLeaseRestMin = 300; // when to ask to extend lease
static const unsigned char DhcpLeaseRenewFraction = 8; // to renw lease when only this fraction of lease is left
// DHCP tick counter to get full seconds
static unsigned char DhcpTicks = 0;
// time of current DHCP action
static unsigned char DhcpInProgress = 0; // if DHCP action is in progress
static unsigned char DhcpRetries = 0; // number of retries left
static unsigned char DhcpRetrySecs = 0; // rest of time for current retry
// current XId
static unsigned char DhcpHaveXId = 0; // if an XId exists at the moment
static unsigned long DhcpXId = 0; // the current XId data
static unsigned int DhcpXIdSecs = 0; // time of XId
// DHCP server and lease time
static unsigned char DhcpActive = 0; // if own IP is leased from DHCP
static unsigned char DhcpServer[4]; // IP address of DHCP server own IP is leased from
static unsigned long DhcpLeaseTime = 0; // total lease time
static unsigned long DhcpLeaseRest = 0; // rest of lease time
// send a DHCP packet
// pData must point to a struct DhcpPacket with IpHdr.Dest, DhcpHdr.XId
// DhcpHdr.Secs, DhcpHdr.Flags and DhcpHdr.YIAddr already initialized
static void DhcpSend( unsigned char * pData, unsigned short Length ) // (extern)
{
struct DhcpPacket * pDhcpPack;