spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
spinn_net.c File Reference

Ethernet/IP support routines for Spinnaker. More...

#include "spinnaker.h"
#include "sark.h"
#include "scamp.h"
#include "spinn_net.h"
#include <string.h>

Data Structures

struct  arp_entry
 An ARP cache entry. More...
 

Macros

#define MAX_ARP_ENTRIES   5
 Max size of ARP cache.
 

Functions

static void eth_discard (void)
 Clear the ethernet receive buffer.
 
void eth_init (uchar *mac)
 Initialise the ethernet subsystem.
 
uint ipsum (uchar *d, uint len, uint sum)
 Compute an IP checksum.
 
void copy_mac (const uchar *f, uchar *t)
 Copy MAC address.
 
void copy_ip (const uchar *f, uchar *t)
 Copy IP address.
 
uint cmp_ip (const uchar *a, const uchar *b)
 Compare IP addresses.
 
void copy_ip_hdr (uchar *dest, uint prot, ip_hdr_t *ip, uint len)
 Initialise IP header.
 
void eth_transmit (uchar *buf, uint len, uint type, const uchar *dest)
 Transmit ethernet packet.
 
void eth_transmit2 (uchar *hdr, uchar *buf, uint hdr_len, uint buf_len)
 Transmit ethernet packet.
 
void send_arp_pkt (uchar *buf, const uchar *dest, const uchar *tha, const uchar *tpa, uint type)
 Send an ARP packet.
 
void arp_lookup (iptag_t *iptag)
 Initiate ARP lookup if required. Lookup might be immediate (out of cache) or require network traffic.
 
void arp_pkt (uchar *rx_pkt, uint rx_len, uint tag_table_size)
 ARP packet received handler.
 
void arp_add (uchar *mac, uchar *ip)
 Add a MAC/IP address binding to our ARP cache.
 
void icmp_pkt (uchar *rx_pkt, uint rx_len)
 ICMP packet received handler.
 
void copy_udp (uchar *buf, uint len, uint dest, uint srce)
 Initialise UDP packet header.
 

Variables

srom_data_t srom
 Copy of SROM struct.
 
iptag_t tag_table []
 Table of all IPTags.
 
const uchar bc_mac [] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
 Broadcast MAC address.
 
const uchar zero_mac [] = {0, 0, 0, 0, 0, 0}
 Zero MAC address.
 
static struct arp_entry arp_entries [MAX_ARP_ENTRIES]
 The ARP cache.
 
static uint next_arp_entry = MAX_ARP_ENTRIES
 Which is the next ARP cache entry to allocate (or evict and reuse)
 

Detailed Description

Ethernet/IP support routines for Spinnaker.

Author
Steve Temple, APT Group, School of Computer Science

Data Structure Documentation

◆ arp_entry

struct arp_entry

An ARP cache entry.

This remembers what MAC address to send an ethernet packet to in order to deliver an IP packet to a particular address. That MAC address might be the address of a router, not the target machine.

Data Fields
uchar mac[6] The MAC address.
uchar ip[4] The IP address.
struct arp_entry * next Next entry in use.

Function Documentation

◆ eth_init()

void eth_init ( uchar mac)

Initialise the ethernet subsystem.

Parameters
[in]macOur MAC address

◆ ipsum()

uint ipsum ( uchar d,
uint  len,
uint  sum 
)

Compute an IP checksum.

Parameters
[in]dThe data to checksum
[in]lenNumber of bytes in data
[in]sumInitial value; allows chaining of summing
Returns
the checksum

◆ copy_mac()

void copy_mac ( const uchar f,
uchar t 
)

Copy MAC address.

Parameters
[in]fWhere to copy from. Must be at least half-word aligned
[out]tWhere to copy to. Must be at least half-word aligned

◆ copy_ip()

void copy_ip ( const uchar f,
uchar t 
)

Copy IP address.

Parameters
[in]fWhere to copy from. Must be at least half-word aligned
[out]tWhere to copy to. Must be at least half-word aligned

◆ cmp_ip()

uint cmp_ip ( const uchar a,
const uchar b 
)

Compare IP addresses.

Parameters
[in]aFirst address to compare
[in]bSecond address to compare
Returns
True if the addresses are equal, false otherwise

◆ copy_ip_hdr()

void copy_ip_hdr ( uchar dest,
uint  prot,
ip_hdr_t ip,
uint  len 
)

Initialise IP header.

Parameters
[in]destDestination address
[in]protProtocol to use
[in,out]ipPacket with header to initialise, copying dest into. The payload must have already been placed in the packet.
[in]lenThe length of the payload in the packet.

◆ eth_transmit()

void eth_transmit ( uchar buf,
uint  len,
uint  type,
const uchar dest 
)

Transmit ethernet packet.

Parameters
[in,out]bufThe buffer containing the packet to send. Will have the parts that are the ethernet header modified.
[in]lenLength of buffer (headers and payload)
[in]typeThe type of ethernet packet to send
[in]destThe destination MAC address

◆ eth_transmit2()

void eth_transmit2 ( uchar hdr,
uchar buf,
uint  hdr_len,
uint  buf_len 
)

Transmit ethernet packet.

Parameters
[in]hdrThe ethernet header, already prepared.
[in]bufThe buffer containing the payload to send.
[in]hdr_lenLength of header, hdr
[in]buf_lenLength of payload, buf

◆ send_arp_pkt()

void send_arp_pkt ( uchar buf,
const uchar dest,
const uchar tha,
const uchar tpa,
uint  type 
)

Send an ARP packet.

Parameters
[in,out]bufBuffer containing ARP packet. Payload must have been set.
[in]destDestination MAC address
[in]thaTarget hadrware address
[in]tpaTarget protocol address
[in]typeOpcode (e.g., ARP_REQ)

◆ arp_lookup()

void arp_lookup ( iptag_t iptag)

Initiate ARP lookup if required. Lookup might be immediate (out of cache) or require network traffic.

Parameters
[in,out]iptagThe IPTag that needs the lookup done. Will be updated with results when available.

◆ arp_pkt()

void arp_pkt ( uchar rx_pkt,
uint  rx_len,
uint  tag_table_size 
)

ARP packet received handler.

Parameters
[in]rx_pktThe received packet
[in]rx_lenThe length of the received packet
[in]tag_table_sizeHow large is our tag table?

◆ arp_add()

void arp_add ( uchar mac,
uchar ip 
)

Add a MAC/IP address binding to our ARP cache.

Parameters
[in]macThe MAC address
[in]ipThe IP address

◆ icmp_pkt()

void icmp_pkt ( uchar rx_pkt,
uint  rx_len 
)

ICMP packet received handler.

Parameters
[in]rx_pktThe received packet
[in]rx_lenThe length of the received packet

◆ copy_udp()

void copy_udp ( uchar buf,
uint  len,
uint  dest,
uint  srce 
)

Initialise UDP packet header.

Parameters
[in,out]bufThe UDP packet, header and payload. Payload must have been initialised.
[in]lenLength of payload.
[in]destDestination port.
[in]srceSource port.