/* BlueDataDistributor - data distribution module from ethernet to 32 serial ports
* version 0.1.1 date 2006-10-07
* Copyright (C) 2006 Stefan Schuermans <stefan@blinkenarea.org>
* a BlinkenArea project - http://www.blinkenarea.org/
*/
#include "arp.h"
#include "config.h"
#include "ethernet.h"
#include "ip.h"
#include "macros.h"
#include "nethelp.h"
// timing parameters
#define ArpTicksMax 150 // maximum age of ARP table entries (in 200ms steps)
#define ArpNoMacTicksMax 50 // maximum age of ARP table entries without MAC (in 200ms steps)
#define ArpRetryTicks 8 // time after which to retry ARP query (must be power of 2, in 200ms steps)
// ARP table
#define ArpTabFlagInUse 0x01
#define ArpTabFlagMacOk 0x02
struct ArpTable
{
unsigned char Flags; // flags - see constants
unsigned char Ticks; // age of entry in 200ms steps
unsigned char Mac[6];
unsigned char Ip[4];
} ArpTab[12];
// initialize
void ArpInit( void ) // (extern)
{
unsigned char i;
// empty ARP tabale
for( i = 0; i < count( ArpTab ); i++ )
ArpTab[i].Flags = 0;
}
// send an ARP request
static void ArpSendRequest( unsigned char * pIp )
{
struct ArpPacket ArpRequest;
// build ARP request
ArpRequest.ArpHdr.HwType = htons( 0x0001 ); // ethernet
ArpRequest.ArpHdr.ProtoType = htons( 0x0800 ); // IP
ArpRequest.ArpHdr.HwLen = 0x06; // length of a MAC address
ArpRequest.ArpHdr.ProtoLen = 0x04; // length of an IP address
ArpRequest.ArpHdr.Op = htons( 0x0001 ); // ARP request
mac_cpy( ArpRequest.ArpHdr.SrcMac, ConfigMac ); // own MAC