/* BlueDataDistributor - data distribution module from ethernet to 32 serial ports
* version 0.1.1 date 2006-10-07
* Copyright (C) 2006 Stefan Schuermans <stefan@blinkenarea.org>
* a BlinkenArea project - http://www.blinkenarea.org/
*/
#include <stdio.h>
#include "config.h"
#include "checksum.h"
#include "ethernet.h"
#include "ip.h"
#include "macros.h"
#include "nethelp.h"
#include "random.h"
#include "tcp.h"
#define TCP_URG 0x20
#define TCP_ACK 0x10
#define TCP_PSH 0x08
#define TCP_RST 0x04
#define TCP_SYN 0x02
#define TCP_FIN 0x01
#define TCP_FLAGS 0x3F
#define TcpResendTicks 5 // time after which to resend a packet not ACKed (in 200ms steps, max. 255)
#define TcpTimeWaitTicks 20 // time to wait in TIME_WAIT state (in 200ms steps, max. 255)
#define TcpTimeoutTicks 50 // maximum idle time of connection before it is reset (in 200ms steps, max. 255)
#define TcpMaxLifeTimeTicks 150 // maximum lifetime of connection before it is reset (in 200ms steps, max. 255)
// TCP connections
struct TcpConnection TcpConns[8];
// initialize
void TcpInit( void ) // (extern)
{
unsigned char i;
// set all connections to closed
for( i = 0; i < count( TcpConns ); i++ )
TcpConns[i].State = TCP_CLOSED;
}
// send a TCP packet
// pData must point to a struct TcpPacket with TcpHdr.SrcPort, TcpHdr.DestPort,
// TcpHdr.SeqNo, TcpHdr.AckNo, TcpHdr.WndSz and IpHdr.Dest already initialized
static void TcpSendPacket( unsigned char * pData, unsigned short Length, unsigned char optLen, unsigned char flags )
{
struct TcpPacket * pTcpPack;
unsigned int chk;