/* vim: set filetype=c:
 *
 **************************************************************************
 *
 * Boot-ROM-Code to load an operating system across a TCP/IP network.
 *
 * Module:  arp.h86
 * Purpose: Definitions for implementing the ARP protocol
 * Entries: none
 *
 **************************************************************************
 *
 * Copyright (C) 1995-2007 Gero Kuhlmann <gero@gkminix.han.de>
 *
 *  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
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: arp.h86,v 1.5 2007/01/06 18:30:47 gkminix Exp $
 */

#ifndef KERNEL_NET_ARP_H86
#define KERNEL_NET_ARP_H86


/*
 **************************************************************************
 *
 * We need some includes before we can include this file
 */
#include <common.h86>
#include <net/ethernet.h86>



/*
 **************************************************************************
 *
 * ARP timeout in timer ticks when sending a request
 */
#define ARP_TIMEOUT	1		/* Timeout is 1 sec initially	*/
#define ARP_COUNTS	8		/* Max. 8 retries		*/



/*
 **************************************************************************
 *
 * ARP protocol opcodes:
 */
#define	ARPOP_REQUEST	1		/* ARP request			*/
#define	ARPOP_REPLY	2		/* ARP reply			*/



/*
 **************************************************************************
 *
 * ARP protocol address identifiers:
 */
#define ARPPROT_IP	0x0800		/* IP identifier		*/
#define ARPPROT_ARP	0x0806		/* ARP identifier		*/
#define ARPPROT_RARP	0x8035		/* RARP identifier		*/



/*
 **************************************************************************
 *
 * Ethernet ARP header:
 */
struct arphdr
{
	__u16	ar_hrd;			/* format of hardware address	*/
	__u16	ar_pro;			/* format of protocol address	*/
	__u8 	ar_hln;			/* length of hardware address	*/
	__u8 	ar_pln;			/* length of protocol address	*/
	__u16	ar_op;			/* ARP opcode (command)		*/
	__u8 	ar_sha[ETH_ALEN];	/* sender hardware address	*/
	__u32	ar_sip;          	/* sender IP address		*/
	__u8 	ar_tha[ETH_ALEN];	/* target hardware address	*/
	__u32	ar_tip;          	/* target IP address		*/
};



/*
 **************************************************************************
 * 
 * ARP cache structure
 */
struct arp_cache {
	t_ipaddr ipaddr;			/* IP address		*/
	__u8     hwaddr[ETH_ALEN];		/* hardware address	*/
};

#define ARPNUM 4		/* number of entries in ARP cache	*/



/*
 **************************************************************************
 *
 * Functions in ARP module:
 */

/* Resolve IP address and return pointer to hardware address */
extern short ip_resolve(t_ipaddr myip, t_ipaddr ip, t_ipaddr gw, __u8 *hwaddr);

/* Process a received ARP packet */
extern void arp_recv(size_t bufsize);

#endif

