/*
    Copyright 2001 (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/Attic/NetTftp.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_TFTP_H_
#define _NET_TFTP_H_


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

// Socket stuff
#define DEFAULT_DEVICE			0

// TFTP types
#define NETTFTP_OPCODE_RREQUEST	1
#define NETTFTP_OPCODE_WREQUEST	2
#define NETTFTP_OPCODE_DAT			3
#define NETTFTP_OPCODE_ACK			4
#define NETTFTP_OPCODE_ERROR		5

// TFTP errors
#define NETTFTP_UNDEF_ERR				0
#define NETTFTP_NOTFOUND_ERR		1
#define NETTFTP_ACCESS_ERR			2
#define NETTFTP_DISK_ERR				3
#define NETTFTP_ILL_ERR					4
#define NETTFTP_ID_ERR					5
#define NETTFTP_EXIST_ERR				6
#define NETTFTP_USER_ERR				7

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

// Loops & timeouts
#define MAX_TRY							2
#define MAX_OUT_OF_SYNC			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 TFTP_SERVER_PORT		69
#define TFTP_CLIENT_PORT		1067	// XXX should be randowm

// Maximum Size of a TFTP Packet (RFC 1350)
#define TFTP_MAX_SIZE				516
#define TFTP_MIN_SIZE				4

typedef struct Tftp_Ack_Head
{
  uint16	opc;
  uint16	block;
}
Tftp_Ack_Head_t;
typedef Tftp_Ack_Head_t *Tftp_Ack_Ptr_t;

typedef struct Tftp_Data_Head
{
  uint16  opc;
  uint16  block;
  char		data;
}
Tftp_Data_Head_t;
typedef Tftp_Data_Head_t *Tftp_Data_Ptr_t;


// function prototypes
void netTftp(ThreadId arg);
int sndTftpPacket(ThreadId sock, char* MyPack, long length);
int rcvTftpPacket(ThreadId sock, char* buffer, long* len, unsigned short *port);
int tftpSelect(ThreadId dev, long timeout);


#endif
