Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Related Pages  

Ethernet IP Stack

Very simple IP over Ethernet implementation. More...

Data Structures

struct  ARPENTRY
struct  ARPFRAME
struct  ether_arp
struct  ether_header
struct  ip
struct  nic_pkt_header
struct  udphdr

Defines

#define ARPHRD_ETHER   1
 ethernet hardware format

#define ARPOP_REQUEST   1
 request to resolve address

#define ARPOP_REPLY   2
 response to previous request

#define NIC_PAGE_SIZE   0x100
#define NIC_START_PAGE   0x40
#define NIC_STOP_PAGE   0x60
#define NIC_TX_PAGES   6
#define NIC_TX_BUFFERS   2
#define NIC_FIRST_TX_PAGE   NIC_START_PAGE
#define NIC_FIRST_RX_PAGE   (NIC_FIRST_TX_PAGE + NIC_TX_PAGES * NIC_TX_BUFFERS)
#define TX_PAGES   12
#define ETHERTYPE_IP   0x0008
 IP protocol.

#define ETHERTYPE_ARP   0x0608
 Address resolution protocol.

#define INADDR_BROADCAST   (u_long)0xffffffff
#define IPPROTO_IP   0
 Dummy for IP.

#define IPPROTO_ICMP   1
 Control message protocol.

#define IPPROTO_TCP   6
 Transmission control protocol.

#define IPPROTO_UDP   17
 User datagram protocol.

#define IPVERSION   4
 IP protocol version.

#define IP_DF   0x4000
 Don't fragment flag.

#define IP_MF   0x2000
 More fragments flag.

#define IP_OFFMASK   0x1fff
 Mask for fragmenting bits.


Typedefs

typedef ether_arp ETHERARP
 Ethernet ARP protocol type.

typedef ether_header ETHERHDR
typedef ip IPHDR
typedef udphdr UDPHDR

Functions

int ArpRequest (u_long dip, u_char *dmac)
 Request the MAC address of a specified IP address.

void ArpRespond (void)
 Process incoming ARP packets.

int NicReset (void)
 Reset the NIC.

void NicInit (void)
 Initialize the NIC.

int EtherOutput (u_char *dmac, u_short type, u_short len)
 Send an Ethernet frame.

int EtherInput (u_short type, u_short tms)
 Receive an Ethernet frame.

u_short IpChkSumPartial (u_short partial_csum, void *buf, u_short count)
 Calculates a partial IP checksum over a block of data.

u_short IpChkSum (u_short partial_csum, void *buf, u_short count)
 Calculates an the final IP checksum over a block of data.

int IpInput (u_char proto, u_short tms)
 Receive an IP packet with the specified protocol type.

int IpOutput (u_long dip, u_char proto, u_short len)
int UdpInput (u_short port, u_short tms)
 Receive an UDP datagram on a specified port.

int UdpOutput (u_long dip, u_short dport, u_short sport, u_short len)
 Send an UDP datagram.


Variables

ARPENTRY ae
ARPFRAME arpframe
u_char mac [6] = { 0x00,0x06,0x98,0x00,0x00,0x00 }
volatile u_charbase = (u_char *)0x8300

Detailed Description

Very simple IP over Ethernet implementation.


Function Documentation

int ArpRequest u_long    dip,
u_char   dmac
 

Request the MAC address of a specified IP address.

Parameters:
dip  IP address in network byte order.
dmac  Points to the buffer, that will receive the MAC address.
Returns:
0 on success, -1 otherwise.

Definition at line 114 of file arp.c.

void ArpRespond void   
 

Process incoming ARP packets.

We do not really respond to ARP requests.

Definition at line 176 of file arp.c.

int EtherInput u_short    type,
u_short    tms
 

Receive an Ethernet frame.

Parameters:
tms  Return with timeout after the specified number of waiting loops. On a 14 Mhz ATmega this value represents approximately the number of milliseconds to wait.
Returns:
The number of bytes received, 0 on timeout or -1 in case of a failure.

Definition at line 279 of file ether.c.

References nic_pkt_header::ph_nextpg, nic_pkt_header::ph_size, and nic_pkt_header::ph_status.

int EtherOutput u_char   dmac,
u_short    type,
u_short    len
 

Send an Ethernet frame.

Parameters:
dmac  Destination MAC address.
type  Frame type.
len  Frame size.
Returns:
0 on success, -1 otherwise.

Definition at line 183 of file ether.c.

u_short IpChkSum u_short    partial_csum,
void *    buf,
u_short    count
 

Calculates an the final IP checksum over a block of data.

Unlike the partial checksum in NutIpChkSumPartial(), this function takes the one's complement of the final result, thus making it the full checksum.

Definition at line 157 of file ip.c.

u_short IpChkSumPartial u_short    partial_csum,
void *    buf,
u_short    count
 

Calculates a partial IP checksum over a block of data.

Note that this returns the checksum in network byte order, and thus does not need to be converted via hton16(), etc. Of course this means that we mustn't use this value for normal arithmetic!

This is a partial checksum because it doesn't take the 1's complement of the overall sum.

Note:
by Harald Kipp: Yes, it looks wrong. I assume that this will not work for all packet sizes. Not yet confirmed.

Definition at line 99 of file ip.c.

int IpInput u_char    proto,
u_short    tms
 

Receive an IP packet with the specified protocol type.

This function calls EtherInput(). Any incoming Ethernet frame, which is not of the specified type will be discarded.

Parameters:
proto  Protocol type.
tms  Return with timeout after the specified number of waiting loops. On a 14 Mhz ATmega this value represents approximately the number of milliseconds to wait.
Returns:
The number of bytes received, 0 on timeout or -1 in case of a failure.

Definition at line 177 of file ip.c.

int IpOutput u_long    dip,
u_char    proto,
u_short    len
 

Returns:
0 on success, -1 otherwise.

Definition at line 242 of file ip.c.

void NicInit void   
 

Initialize the NIC.

For further description of the initialization please refer to the original Ethernut code.

Definition at line 126 of file ether.c.

int NicReset void    [static]
 

Reset the NIC.

Returns:
0 on success, -1 otherwise.

Definition at line 102 of file ether.c.

int UdpInput u_short    port,
u_short    tms
 

Receive an UDP datagram on a specified port.

This function calls IpInput(). Any incoming Ethernet frame, which is not an UDP datagram to the specified port will be discarded.

Parameters:
port  UDP port to listen to.
tms  Return with timeout after the specified number of waiting loops. On a 14 Mhz ATmega this value represents approximately the number of milliseconds to wait.
Returns:
The number of bytes received, 0 on timeout or -1 in case of a failure.

Definition at line 115 of file udp.c.

int UdpOutput u_long    dip,
u_short    dport,
u_short    sport,
u_short    len
 

Send an UDP datagram.

This function fills the UDP header of the global send frame and calls IpOutput().

Parameters:
dip  Destination IP address in network byte order.
dport  Destination port.
sport  Source port.
len  Number of data bytes to transmit.
Returns:
0 on success, -1 otherwise.

Definition at line 149 of file udp.c.


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