Ethernet
[Base Protocols]

RFC 894 IP over Ethernet. More...

Collaboration diagram for Ethernet:

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.

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:
type Ethernet protocol type processed by this handler.
mask Ethernet protocol type mask.
hdlr Pointer 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, and ether_demux.

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:
dev Identifies the device that received the frame.
nb Pointer to a network buffer structure containing the ethernet frame.

Definition at line 156 of file ethin.c.

References ether_demux, ETHERHDR::ether_type, ETHERTYPE_ARP, ETHERTYPE_IP, ntohs, NutArpInput(), NutIpInput(), and NutNetBufFree().

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:
dev Identifies the device to use.
type Type of this frame, either ETHERTYPE_IP or ETHERTYPE_ARP.
ha MAC address of the destination, set null for broadcasts.
nb Network 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 ETHERHDR::ether_dhost, ETHERHDR::ether_shost, ETHERHDR::ether_type, htons, memcpy(), memset(), NBAF_DATALINK, NutNetBufAlloc(), and NutNetBufFree().


Variable Documentation

int(* ether_demux)(NUTDEVICE *, NETBUF *)

Pointer to an optional demultiplexer.

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

Referenced by NutEtherInput(), and NutRegisterEthHandler().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/