- Timestamping management added - Errors due to reading uninitialized data in ARP fixed - EthInterface reworked, incoming packet notification and payload readout separated (through which fixing concurrent access problems) - RX and TX offloads added - Capability to add a packet sieve layer without prior registration of specific packet class added (this makes it possible to register arbitrary EtherType connection blocks, for example)
94 lines
3.0 KiB
C
94 lines
3.0 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"
|
|
#include "connection_block.h"
|
|
#include "msg_queue.h"
|
|
#include "prefab/conn_blocks/ipv4/ip_assembler.h"
|
|
#include "etherlib_options.h"
|
|
|
|
/**
|
|
* Ethernet interface low level definition.
|
|
*/
|
|
typedef struct EthIODef_ {
|
|
int (*llTxTrigger)(struct EthIODef_ * io, MsgQueue * mq); ///< Function pointer to low-level transmit function trigger
|
|
int (*llTxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Transmission done (interrupt) callback
|
|
int (*llLinkChg)(struct EthIODef_ * io, int linkState); ///< Link change interrupt
|
|
int (*llRxStore)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback
|
|
int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt
|
|
int (*llRxRead)(struct EthIODef_ * io, MsgQueue * mq); ///< Read received packets
|
|
int (*llRxNotify)(struct EthIODef_ * io); ///< Notify of received packets
|
|
void * tag; ///< Some arbitrary tagging
|
|
|
|
} EthIODef;
|
|
|
|
/**
|
|
* Ethernet interface capabilities
|
|
*/
|
|
typedef enum {
|
|
ETHINF_CAP_NONE = 0,
|
|
ETHINF_CAP_TX_CRC_OFFLOAD = 1,
|
|
ETHINF_CAP_TX_IPCHKSUM_OFFLOAD = 2,
|
|
ETHINF_CAP_TX_TCPUDPCHKSUM_OFFLOAD = 4,
|
|
ETHINF_CAP_RX_IPCHKSUM_OFFLOAD = 8,
|
|
ETHINF_CAP_RX_TCPUDPCHKSUM_OFFLOAD = 16,
|
|
ETHINF_CAP_ALL_RX_TX_CHECKSUM_OFFLOADS = 0b11111,
|
|
} EthIntfCap;
|
|
|
|
/**
|
|
* Ethernet interface representation.
|
|
*/
|
|
typedef struct EthInterface_ {
|
|
PcktSieve sieve; ///< Packet sieve
|
|
EthIODef * ioDef; ///< Low-level IO definitions
|
|
EthernetAddress mac; ///< Ethernet address
|
|
uint32_t capabilities; ///< Ethernet interface capabilities
|
|
ip4_addr ip; ///< IP address
|
|
ip4_addr router; ///< Router IP address
|
|
ip4_addr netmask; ///< Subnet mask
|
|
ip4_addr dns; ///< Domain Name Server
|
|
ArpCache * arpc; ///< ARP cache
|
|
ConnBlock arpCb; ///< ARP connection block
|
|
MsgQueue * txQ; ///< Transmit queue
|
|
MsgQueue * rxQ; ///< Receive queue
|
|
ETHLIB_OS_SEM_TYPE rxSem; ///< Receive queue semaphore
|
|
IPv4Assembler * ipra; ///< IPv4 reassembler
|
|
} 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);
|
|
|
|
/**
|
|
* Notify interface of a received, buffered packet, which needs transferred
|
|
* from the low level Ethernet-driver.
|
|
* @param intf Pointer to Ethernet-interface
|
|
*/
|
|
void ethinf_notify(EthInterface *intf);
|
|
|
|
/**
|
|
* Transmit packet.
|
|
*/
|
|
void ethinf_transmit(EthInterface *intf, const RawPckt *rawPckt);
|
|
|
|
/**
|
|
* Set interface capabilities.
|
|
* @param intf pointer to Ethernet interface
|
|
* @param cap OR-ed bitfield of capabilities
|
|
*/
|
|
void ethinf_set_capabilities(EthInterface *intf, uint32_t cap);
|
|
|
|
#endif //ETHERLIB_ETH_INTERFACE_H
|