EtherLib/eth_interface.h

52 lines
1.5 KiB
C

#ifndef ETHERLIB_ETH_INTERFACE_H
#define ETHERLIB_ETH_INTERFACE_H
#include "packet_sieve.h"
#include "prefab/packet_parsers/packet_parsers.h"
#include "prefab/packet_parsers/ipv4_types.h"
#include "arp_cache.h"
/**
* Ethernet interface low level definition.
*/
typedef struct EthIODef_ {
int (*llTx)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Function pointer to low-level transmit function
int (*llTxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Transmission done (interrupt) callback
int (*llLinkChg)(struct EthIODef_ * io, int linkState); ///< Link change interrupt
int (*llRxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback
int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt
void * tag; ///< Some arbitrary tagging
} EthIODef;
/**
* Ethernet interface representation.
*/
typedef struct EthInterface_ {
PcktSieve sieve; ///< Packet sieve
EthIODef * ioDef; ///< Low-level IO definitions
EthernetAddress mac; ///< Ethernet address
ip4_addr ip; ///< IP address
ArpCache * arpc; ///< ARP cache
} EthInterface;
/**
* Allocate a new Ethernet interface
* @param io Low-level IO definitions
* @return new interface instance
*/
EthInterface *ethintf_new(EthIODef * io);
/**
* Receive uncooked packet.
* @param rawPckt
*/
void ethinf_receive(EthInterface *intf, const RawPckt *rawPckt);
/**
* Transmit packet.
*/
void ethinf_transmit(EthInterface *intf, const RawPckt *rawPckt);
#endif //ETHERLIB_ETH_INTERFACE_H