/*
    Copyright 2000 (c) by Claudio Jeker,
    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/NetDevice.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 _NETIFACE_H_
#define _NETIFACE_H_

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

/* Interface types ETHER, PPP, TOKEN et al. (8bit) */
#define IFT_UNKNOWN 0
#define IFT_ETHER	0x1

/* Interface states UP, DOWN, etc (8bit) */
#define IFS_UNKNOWN 0 /* something needs to be defined */


#define IF_NAME_SIZE 14 /* n*4 + 2 to pad it with the u16 index field */

typedef struct NetAddressDesc_t *NetAddress;
typedef struct NetDeviceDesc_t *NetDevice;

typedef struct NetAddressDesc_t
{
  NetAddress prev;
  NetAddress next;
  NetDevice device;
  NetAttrs addr;
  u16 index; /* numeric abbreviation for this alias */
  u16 pad;
}
NetAddressDesc;

typedef struct NetDeviceDesc_t
{
  ThreadId	device;		/* "pointer" to device */
  ThreadId	queue;		/* "pointer" to queue */
  char		name[IF_NAME_SIZE];
  u16			index;		/* numeric abbreviation for this device */
  NetAddress	addrList;	/* addresses of this device */
  /* the HARDWARE address is stored under addrList->addr together with the
   * first main addresses (IP and IPv6) */
  /* generic interface information */
  u8	type;				/* ethernet, tokenring, etc. */
  u8	linkstate;			/* current link state */
  u16	flags;				/* generic flags like BROADCAST */
  u32	mtu;				/* maximum transmission unit */
  u32	baudrate;			/* linespeed */
  /* XXX until now this seems to be enough */
#ifdef NET_STATISTICS
  /* volatile statistics */
  u32	inpackets;		/* packets received on interface */
  u32	inerrors;		/* input errors on interface */
  u32	outpackets;		/* packets sent on interface */
  u32	outerrors;		/* output errors on interface */
  u32	collisions;		/* collisions on csma interfaces */
  u32	inbytes;		/* total number of octets received */
  u32	outbytes;		/* total number of octets sent */
  u32	inmcasts;		/* packets received via multicast */
  u32	outmcasts;		/* packets sent via multicast */
  u32	inqdrops;		/* dropped on input, this interface */
  u32	noproto;		/* destined for unsupported protocol */
  u32 lastchange;		/* last updated */
#endif
}
NetDeviceDesc;

short netdevGetType(u8 type);
int netdevGet(u16 devNr, NetDevice* this);
int netdevAdd(ThreadId device, u16 major, u16 minor, u8 type, char *name);
u32 getMaxMTU(u8 type);
void netdevStartAll(void);
int netdevInit(void);
int netdevGetHWAddr (int deviceNr, NetAttr* avec, unsigned long *len);
int netdevSetAddr (int deviceNr, NetAttr* avec, unsigned long len,
                   unsigned long index);
int netdevIsLocal(NetDevice this, NetAttr* avec, unsigned long len);
#endif

