/*
    NullModule.c, Copyright  (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/Modules/NullModule.c,v $
    Author(s):
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 2922 $
    Creation Date:
    Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $  by: $Author: baderma $
 
*/
#include "Topsy.h"
#include "Syscall.h"
#include "Support.h"
#include "NetModulesNew.h"
#include "NetAttr.h"
#include "LWThreads.h"
#include "NullModule.h"


void netNullModuleInit(NetModule this)
{
  /* e.g. netattrSet (this->attributes, NETATTR_IP_TTL, 64); */
  return;
}


int netNullModuleConfig(NetModule this, Message *msg)
{
  /* 	unsigned long	len = msg->msg.netConf.ModuleConf.len;
  	unsigned long	i;
  	NetAttr			*a = msg->msg.netConf.ModuleConf.attrVec;
  	int				exitCode = 0;
   
   
  	for ( i = 0; i < len ; i++) {
  		switch ( a[i].key ) {
  			// add all known keys here
  			case ATTR1:
  			case ATTR2:
  				if ( msg->id == NET_CONF_MODULESET ) {
  					// set attributes
  					if (! netattrSet(this->attributes, a[i].key, a[i].data) ) {
  						netdbgPrintf(0, "netmodConfigure: netattrSet failed (%i, %i)\n",
  								a[i].key, a[i].data);
  						CONF_FAILEDPLUS(exitCode);
  						return exitCode;
  					}
  					CONF_SUCCEDPLUS(exitCode);
  				} else if ( msg->id == NET_CONF_MODULEGET ) {
  					if (!netattrGet(this->attributes, a[i].key, &(a[i].data))) {
  						netdbgPrintf(0, "netmodConfigure: netattrGet failed (%i)\n",
  								a[i].key);
  						CONF_FAILEDPLUS(exitCode);
  						return exitCode;
  					}
  					CONF_SUCCEDPLUS(exitCode);
  				} else {
  					netdbgPrintf(0, "netmodConfigure: AIIEEE, got hit by a bus\n");
  					CONF_FAILEDPLUS(exitCode);
  					return exitCode;
  				}					
  				break;
  			default:
  				netdbgPrintf(0, "netmodConfigure: unknown key %i\n", a[i].key);
  				CONF_IGNOREPLUS(exitCode);
  		}
  	}
  	return exitCode;
  */
  return 0;
}


void netNullModuleMain(LWPool lw, ThreadArg arg)
{
  NetModule		modDesc = (NetModule) arg;
  NetBuf			data;
  NetAttrs		meta;


  while (1)
  {
    netmodRecv(lw, &data, &meta);
    PACKSTART(modDesc);
    // since I'm a null module I just pass it on :-)
    PACKDONE(modDesc);
    netmodSend(lw, CHAINNEXT(modDesc), data, meta);
  }
}
