eth_interface development

This commit is contained in:
Wiesner András 2022-12-08 15:06:30 +01:00
parent 586a9ba733
commit c14d3b192a
3 changed files with 25 additions and 10 deletions

View File

@ -6,10 +6,22 @@
#include "dynmem.h"
#include "utils.h"
EthInterface *ethintf_new() {
static int ethintf_llrecv(EthIODef * io, const RawPckt * pckt) {
ethinf_receive((EthInterface *) io->tag, pckt);
return 0;
}
static void ethintf_register(EthInterface * intf) {
intf->ioDef->tag = intf;
intf->ioDef->llRxDone = ethintf_llrecv;
}
EthInterface *ethintf_new(EthIODef * io) {
EthInterface * ethIntf = (EthInterface *)dynmem_alloc(sizeof(EthInterface));
ASSERT_NULL(ethIntf);
memset(&ethIntf->sieve.layer0, 0, sizeof(PcktSieveLayer));
ethIntf->ioDef = io;
ethintf_register(ethIntf);
return ethIntf;
}
@ -18,5 +30,5 @@ void ethinf_receive(EthInterface *intf, const RawPckt *rawPckt) {
}
void ethinf_transmit(EthInterface *intf, const RawPckt *rawPckt) {
intf->ioDef.llTx(rawPckt);
intf->ioDef->llTx(&(intf->ioDef), rawPckt);
}

View File

@ -4,24 +4,27 @@
#include "packet_sieve.h"
#include "prefab/packet_parsers/packet_parsers.h"
typedef struct {
int (*llTx)(const RawPckt * rawPckt); ///< Function pointer to low-level transmit function
int (*llTxDone)(const RawPckt * rawPckt); ///< Transmission done (interrupt) callback
int (*llLinkChg)(int linkState); ///< Link change interrupt
int (*llError)(int error); ///< Low-level error interrupt
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;
typedef struct EthInterface_ {
PcktSieve sieve; ///< Packet sieve
EthIODef ioDef; ///< Low-level IO definitions
EthIODef * ioDef; ///< Low-level IO definitions
EthernetAddress mac; ///< Ethernet address
} EthInterface;
/**
* Allocate a new Ethernet interface
* @param io Low-level IO definitions
* @return new interface instance
*/
EthInterface * ethintf_new();
EthInterface *ethintf_new(EthIODef * io);
/**
* Receive uncooked packet.

View File

@ -36,5 +36,5 @@ void ethlib_init() {
E.pcktReg = packreg_new(); // create new packet registry
register_packet_parsers(); // register packet parsers
E.ethIntf = ethintf_new(); // create new Ethernet interface
//E.ethIntf = ethintf_new(); // create new Ethernet interface
}