145 lines
4.3 KiB
C
145 lines
4.3 KiB
C
#ifndef ETHERLIB_ETH_INTERFACE_H
|
|
#define ETHERLIB_ETH_INTERFACE_H
|
|
|
|
#include <stdbool.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"
|
|
#include "etherlib/prefab/packet_parsers/dhcp.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;
|
|
|
|
struct EthInterface_;
|
|
|
|
typedef void (*EthIntfEvtCb)(struct EthInterface_ * intf);
|
|
|
|
typedef enum {
|
|
ETH_EVT_LINK_CHANGE = 0,
|
|
ETH_EVT_IP_CHANGE = 1
|
|
} EthIntfEvIndex;
|
|
|
|
/**
|
|
* Ethernet interface event callback table
|
|
*/
|
|
typedef struct {
|
|
EthIntfEvtCb linkChange; ///< Link change event
|
|
EthIntfEvtCb ipChange; ///< IP-address changed
|
|
} EthIntfEventCbTable;
|
|
|
|
/**
|
|
* 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
|
|
DhcpState * dhcp; ///< DHCP control block (allocated only, if DHCP operation is initiated)
|
|
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
|
|
EthIntfEventCbTable evtCbTable; ///< Event callback table
|
|
bool linkState; ///< Interface link state
|
|
} 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);
|
|
|
|
/**
|
|
* Set Ethernet event callback.
|
|
* @param intf pointer to Ethernet interface
|
|
* @param idx index of Ethernet event
|
|
* @param cb callback function pointer
|
|
*/
|
|
void ethinf_set_event_callback(EthInterface * intf, EthIntfEvIndex idx, EthIntfEvtCb cb);
|
|
|
|
/**
|
|
* Trigger Ethernet event.
|
|
* @param intf pointer to Ethernet interface
|
|
* @param idx index of Ethernet interface event
|
|
*/
|
|
void ethinf_trigger_event(EthInterface * intf, EthIntfEvIndex idx);
|
|
|
|
/**
|
|
* Set link state.
|
|
* @param intf pointer to Ethernet interface
|
|
* @param ls link state
|
|
*/
|
|
void ethinf_set_link_state(EthInterface * intf, bool ls);
|
|
|
|
/**
|
|
* Get link state.
|
|
* @param intf pointer to Ethernet interface
|
|
*/
|
|
bool ethinf_get_link_state(EthInterface * intf);
|
|
|
|
#endif //ETHERLIB_ETH_INTERFACE_H
|