/* ARP vrstva komunikacniho modulu pro Ethernet */

#ifndef __ARP_H
#define __ARP_H

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

// Definice
#define MAX_ARP_CACHE			10

#define MAC_Found				1
#define MAC_NotFound			0
#define MAC_Inserted			1
#define MAC_Updated				2
#define MAC_Full				3
#define MAC_Fail				4

#define ARP_Header_len			28			// Delka hlavicky ARP paketu

// Definice OP kodu ARP paketu
#define ARP_OP_REQUEST				0x0001
#define ARP_OP_REPLY				0x0002

// Definice offsetu polozek hlavicky ARP paketu
#define OFFSET_ARP_Header			0x0E
#define OFFSET_ARP_Htype			OFFSET_ARP_Header + 0x00	// Ethernet = 0x0001
#define OFFSET_ARP_Ptype			OFFSET_ARP_Header + 0x02	// IPv4 = 0x0800
#define OFFSET_ARP_Hlen				OFFSET_ARP_Header + 0x04	// Delka MAC adresy v bytech = 6
#define OFFSET_ARP_Plen				OFFSET_ARP_Header + 0x05	// Delka MAC adresy v bytech = 4
#define OFFSET_ARP_OPcode			OFFSET_ARP_Header + 0x06	// 0x0002 = REPLY, 0x0001 = REQUEST
#define OFFSET_ARP_SourceMAC		OFFSET_ARP_Header + 0x08	// MAC adresa zdroje (celkem 6 byte)
#define OFFSET_ARP_SourceIP			OFFSET_ARP_Header + 0x0E	// IP adresa zdroje (celkem 4 byte)
#define OFFSET_ARP_DestMAC			OFFSET_ARP_Header + 0x12	// MAC adresa cile (celkem 6 byte)
#define OFFSET_ARP_DestIP			OFFSET_ARP_Header + 0x18	// IP adresa zdroje (celkem 4 byte)



// Prototypy funkci
void ARP_Set_ARP_Header(uint8_t *buffer, uint16_t OPcode, uint8_t *Source_MAC, uint8_t *Source_IP, 
						uint8_t *Dest_MAC, uint8_t *Dest_IP);
void ARP_Send_ARP_Reply(uint8_t *RX_buffer, uint8_t *TX_buffer);
uint8_t ARP_Get_MAC(uint8_t *IP_address, uint8_t *MAC_address);
uint8_t ARP_InsertCacheEntry(uint8_t *IP_address, uint8_t *MAC_address);
uint8_t ARP_InsertCacheEntryFromRX(uint8_t *RX_buffer);
void ARP_InitCahce(void);

#endif
/* Konec souboru */
