/* IP vrstva komunikacniho modulu pro Ethernet */

#ifndef __IP_H
#define __IP_H

#include "stdint.h"
#include "net.h"

// Definice
#define IP_Header_len				20			// Delka hlavicky IP paketu je 20 bytu (minimum, bez Options casti)
#define IP_Default_TTL				128			// Vychozi hodnota TTL pro odesilane IP ramce

// Definice verze IP protokolu
#define IPv4						(0x04)<<4	// s maskou 11110000

// IP Flags v IP hlavicce
#define IP_DF						0x40		// 01000000 - Don't fragment
#define IP_MF						0x20		// 00100000	- More fragments

// IP Protokol - kody jednotlivych protokolu
#define IP_Protokol_ICMP			0x01		// Who is xxx.xxx.xxx.xxx, ...
#define IP_Protokol_IGMP			0x02
#define IP_Protokol_IP				0x04
#define IP_Protokol_TCP				0x06		// TCP paket (HTTP data)
#define IP_Protokol_UDP				0x11		// UDP paket

// Definice Type of Service - Service code v IP hlavicce
#define SC_IP_NetworkControl		0xE0
#define SC_IP_InternetworkControl	0xC0
#define SC_IP_CRITIC_ECP			0xA0
#define SC_IP_FlashOverride			0x80
#define SC_IP_Flash					0x60
#define SC_IP_Immediate				0x40
#define SC_IP_Priority				0x20
#define SC_IP_Routine				0x00

// Definice offsetu polozek hlavicky v IP paketu
#define OFFSET_IP_Header			0x0E
#define OFFSER_IP_Version			OFFSET_IP_Header + 0x00	// Maska 11110000 = 0xF0
#define OFFSET_IP_Header_Length		OFFSET_IP_Header + 0x00	// Maska 00001111 = 0x0F
#define OFFSET_IP_ServiceCode		OFFSET_IP_Header + 1	// Maska 11111100 = 0xFC
#define OFFSET_IP_TotalLength		OFFSET_IP_Header + 2	// celkem 16 bit = 2 byte
#define OFFSET_IP_Identification	OFFSET_IP_Header + 4	// celkem 16 bit = 2 byte
#define OFFSET_IP_Flags				OFFSET_IP_Header + 6	// Maska 11100000 = 0xE0
#define OFFSET_IP_FragmentOffset	OFFSET_IP_Header + 6	// Maska 00011111 11111111 = 0x1FFF
#define OFFSET_IP_TTL				OFFSET_IP_Header + 8	// celkem 16 bit = 2 byte
#define OFFSET_IP_Protokol			OFFSET_IP_Header + 9	// celkem 8 bit = 1 byte
#define OFFSET_IP_HeaderChecksum	OFFSET_IP_Header + 10	// celkem 16 bit = 2 byte
#define OFFSET_IP_SourceIP			OFFSET_IP_Header + 12	// celkem 32 bit = 4 byte
#define OFFSET_IP_DestIP			OFFSET_IP_Header + 16	// celkem 32 bit = 4 byte
#define OFFSET_IP_Data				OFFSET_IP_Header + 20	// celkem 32 bit = 4 byte

// Definice IP Flags
#define IP_DontFragment				0x40
#define IP_MoreFragment				0x20

// Prototypy funkci
void IP_Set_IP_Header(uint8_t *buffer, uint16_t TotalLen, uint16_t Identification, uint8_t IP_Flags, uint8_t TTL, uint8_t IP_Protokol, uint8_t *Source_IP, uint8_t *Dest_IP);
void IP_CopyTTL(uint8_t *RX_buffer, uint8_t *TX_buffer);
uint8_t *IP_Get_SourceIP(uint8_t *buffer);

#endif
/* Konec souboru */
