Nut/OS  4.10.3
API Reference
Ethernet

RFC 894 IP over Ethernet. More...

Collaboration diagram for Ethernet:

Data Structures

struct  _ETH_PROTOCOLS

Typedefs

typedef struct _ETH_PROTOCOLS ETH_PROTOCOLS
 Linked list of registered Ethernet protocols.

Functions

int NutRegisterEthHandler (uint16_t type, uint16_t mask, int(*hdlr)(NUTDEVICE *, NETBUF *))
 Register an additional Ethernet protocol handler.
void NutEtherInput (NUTDEVICE *dev, NETBUF *nb)
 Handle incoming Ethernet frames.
int NutEtherOutput (NUTDEVICE *dev, uint16_t type, uint8_t *ha, NETBUF *nb)
 Send Ethernet frame.

Variables

int(* ether_demux )(NUTDEVICE *, NETBUF *)
 Pointer to an optional demultiplexer.

Detailed Description

RFC 894 IP over Ethernet.

These routines link the IP layer to the Ethernet driver. Applications do not directly use this.

Todo:
Multicast support.

Typedef Documentation

typedef struct _ETH_PROTOCOLS ETH_PROTOCOLS

Linked list of registered Ethernet protocols.

Definition at line 64 of file ethdemux.c.


Function Documentation

int NutRegisterEthHandler ( uint16_t  type,
uint16_t  mask,
int(*)(NUTDEVICE *, NETBUF *)  hdlr 
)

Register an additional Ethernet protocol handler.

The specified mask will be applied on the type field of incoming frames before compared with the type that had been specified for the handler. If more than one handler is registered for an incoming Ethernet frame, the handler being registered last is called first.

Each handler should return 0 if it processed the frame, in which case it is also assumed, that the handler releases the memory allocated for the NETBUF. Otherwise the handler should return -1, in which case the frame is passed to the next handler that fits.

The protocol types ETHERTYPE_IP and ETHERTYPE_ARP are pre-registered by default and processed by internal handlers after all registered handlers for that frame rejected processing. This allows to install filters on the Ethernet level.

Parameters:
typeEthernet protocol type processed by this handler.
maskEthernet protocol type mask.
hdlrPointer to the protocol handler function. If NULL, the handler will be temporarily disabled.
Returns:
0 on success, -1 otherwise.

Definition at line 125 of file ethdemux.c.

References calloc, ether_demux, _ETH_PROTOCOLS::ethp_input, _ETH_PROTOCOLS::ethp_mask, _ETH_PROTOCOLS::ethp_next, and _ETH_PROTOCOLS::ethp_type.

void NutEtherInput ( NUTDEVICE dev,
NETBUF nb 
)

Handle incoming Ethernet frames.

Splits the Ethernet frame into the data link and the network part. Then the frame is routed to the proper handler, based on the type field in the Ethernet header.

If the frame neither contains an IP nor an ARP type telegram and if no registered handler exists or accepts the frame, then it is silently discarded.

Note:
This routine is called by the device driver on incoming ethernet packets. Applications typically do not call this function.
Parameters:
devIdentifies the device that received the frame.
nbPointer to a network buffer structure containing the ethernet frame.

Definition at line 156 of file ethin.c.

References ether_demux, ether_header::ether_type, ETHERTYPE_ARP, ETHERTYPE_IP, _NETBUF::nb_dl, _NETBUF::nb_nw, ntohs, NutArpInput(), NutIpInput(), NutNetBufFree(), _NBDATA::sz, and _NBDATA::vp.

Here is the call graph for this function:

int NutEtherOutput ( NUTDEVICE dev,
uint16_t  type,
uint8_t ha,
NETBUF nb 
)

Send Ethernet frame.

Send an Ethernet frame of a given type using the specified device.

Parameters:
devIdentifies the device to use.
typeType of this frame, either ETHERTYPE_IP or ETHERTYPE_ARP.
haMAC address of the destination, set null for broadcasts.
nbNetwork buffer structure containing the packet to be sent. The structure must have been allocated by a previous call NutNetBufAlloc() and will be freed if this function returns with an error.
Returns:
0 on success, -1 in case of any errors.

Definition at line 144 of file ethout.c.

References _NUTDEVICE::dev_icb, ether_header::ether_dhost, ether_header::ether_shost, ether_header::ether_type, htons, ifnet::if_mac, ifnet::if_send, memcpy(), memset(), _NETBUF::nb_dl, NBAF_DATALINK, NutNetBufAlloc(), NutNetBufFree(), and _NBDATA::vp.

Here is the call graph for this function:


Variable Documentation

Pointer to an optional demultiplexer.

This pointer will be set on the first call to NutRegisterEthHandler().

Definition at line 135 of file ethin.c.

Referenced by NutEtherInput(), and NutRegisterEthHandler().