/*
    Copyright 2000 (c) by Boris Lutz,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public 
    Licence. A full copy of the GNU GPL is provided in the file COPYING 
    found in the development root of Topsy.
*/
/*
	
    File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Net/NetAutoConfiguration.h,v $
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 2922 $
    Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $  by: $Author: baderma $
 
*/


#ifndef _NET_AUTO_CONFIGURATION_H_
#define _NET_AUTO_CONFIGURATION_H_


#include "NetHAL.h"
#include "Topsy.h"

// Autoconfiguration types
#define NETBOOTP_OPCODE_REQUEST	        1
#define NETBOOTP_OPCODE_REPLY	        2
#define NETBOOTP_HTYPE_ENET		1
#define NETBOOTP_HLEN_ENET		6

// State machine
#define STATE_STARTED		       0
#define STATE_ARP_FILL                 1
#define STATE_CONFIG_IP6_ADRESS        2
#define STATE_ARPLOOKUP                3
#define STATE_DUBLICATE_DETECTION_COMPLETE  4
#define STATE_ARP_ADD_MYIPv6           5
#define STATE_FINISH                   6

#define STATE_UDP_TEST                 10



// Return values
#define RETVAL_OK	          	0
#define RETVAL_FAILED			1

// Loops & timeouts
#define MAX_LOOP			2
#ifdef ia32
#define SELECT_TIMEOUT			1000
#else /* this is for the slow simulator */
#define SELECT_TIMEOUT			2
#endif

// Select call return values
#define NETSELECT_READY			0
#define NETSELECT_TIMEOUT		1
#define NETSELECT_ERROR			2

// Port numbers
#define BOOTP_SERVER_PORT		67
#define BOOTP_CLIENT_PORT		68

// Maximum Size of a DHCP / Autoconfiguration Packet (RFC 2131)
#define BOOTP_MAX_SIZE			576

// Link Local Address
#define LINK_LOCAL_ADDRESS_0            0xfe
#define LINK_LOCAL_ADDRESS_1            0x80




typedef struct NetAutoConfigurationHdr_t
{
  u8		op;
  u8		htype;
  u8		hlen;
  u8		hops;
  u32		xid;
  u16		secs;
  u16		flags;		// Just for DHCP, not used in Autoconfiguration
  u8		ciaddr[4];
  u16		yiaddr[8];
  u8		siaddr[4];
  u8		giaddr[4];
  u8		chaddr[16];
  char	sname[64];
  char	file[128];
}
NetAutoConfigurationHdr;

// function prototypes
void netAutoConfiguration (ThreadId arg);
//int SendAutoconfigurationRequest (ThreadId dev, long sessionID, u8 *myHWAddr);
//int ReadAutoconfigurationReply (ThreadId dev, NetAutoconfigurationHdr* myHdr);
//int selectDevice (ThreadId dev, long timeout);
//int VerifyAutoconfigurationReply (NetAutoconfigurationHdr* myHdr, long sessionID, u8 *myHWAddr);
//int CompareBootReply (NetAutoconfigurationHdr* myHdrA, NetAutoconfigurationHdr* myHdrB);


#endif
