/**
	@file		tcp.h
	@brief 		File containing the headers of tcp protocol packet functions
	@author		Adrían Antoñana Gómez
	@author		Carlos Díaz Cánovas
	@version	beta-2009/01/10

*/
#ifndef TCP_H

#include <stdlib.h>
#include <stdio.h>
#include <ScatterWeb.System.h>
#include <ScatterWeb.CC1020.h>
#include <string.h>
#include "constants.h"
#include "ScatterWeb.System.h"

/*State machine*/
#define	CLOSED_LISTEN 1
#define	SYN_SENT 2
#define	SYN_RECV 3
#define	ESTABLISHED 4
#define	FIN_WAIT1 5
#define	FIN_WAIT2 6
#define	TIME_WAIT 7
#define	CLOSE_WAIT 8
#define LAST_ACK 9
#define	CLOSED 10

/*Fields*/
#define POS_SEQ 0
#define POS_ACK 1
#define POS_FLAGS 2
#define POS_TCP_PAYLOADLEN 3
#define POS_TCP_PAYLOAD 4

/*Flags masks*/
#define F_ACK ((uint8_t)128)
#define F_SYN ((uint8_t)64)
#define F_FIN ((uint8_t)32)

void tcp_process(uint8_t *d, uint8_t msgLen, uint8_t routeLen, uint8_t *route, uint8_t thisNode, uint8_t mode);
void tcp_connect(uint8_t *d, uint8_t *route, uint8_t thisNode);
void tcp_close(uint8_t *d, uint8_t *route, uint8_t thisNode);
void force_close_est();
void force_close_close();

#define TCP_H
#endif
