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.h File Reference

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

Go to the source code of this file.

Data Structures

struct  arp_pkt_t
 ARP packet format. More...
 
struct  udp_hdr_t
 UDP header. More...
 
struct  icmp_hdr_t
 ICMP header. More...
 
struct  mac_hdr_t
 MAC header for ethernet packet. More...
 
struct  ip_hdr_t
 IP packet header. More...
 

Macros

#define MAC_HDR_SIZE   14
 Size of mac_hdr_t.
 
#define IP_HDR_SIZE   20
 Size of ip_hdr_t.
 
#define UDP_HDR_SIZE   8
 Size of udp_hdr_t.
 
#define SDP_PAD_SIZE   2
 Padding added to start of SDP for alignment efficiency.
 
#define IP_HDR_OFFSET   MAC_HDR_SIZE
 Offset from start of packet to start of IP header.
 
#define IP_DATA_OFFSET   (IP_HDR_OFFSET + IP_HDR_SIZE)
 Offset from start of packet to start of IP data.
 
#define UDP_HDR_OFFSET   IP_DATA_OFFSET
 Offset from start of packet to start of UDP header.
 
#define UDP_DATA_OFFSET   (UDP_HDR_OFFSET + UDP_HDR_SIZE)
 Offset from start of packet to start of UDP data.
 
#define ETYPE_IP   0x0800
 Ethernet message type: IP.
 
#define ETYPE_ARP   0x0806
 Ethernet message type: ARP.
 
#define PROT_ICMP   1
 Protocol: ICMP.
 
#define PROT_UDP   17
 Protocol: UDP.
 
#define ARP_REQ   1
 ARP message operation: request.
 
#define ARP_REPLY   2
 ARP message operation: reply.
 
#define ICMP_ECHO_REPLY   0
 ICMP echo (ping) reply.
 
#define ICMP_ECHO_REQ   8
 ICMP echo (ping) request.
 

Functions

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

const uchar bc_mac []
 Broadcast MAC address.
 
const uchar zero_mac []
 Zero MAC address.
 

Detailed Description

Ethernet/IP support routines for Spinnaker.

Author
Steve Temple, APT Group, School of Computer Science

Data Structure Documentation

◆ arp_pkt_t

struct arp_pkt_t

ARP packet format.

Data Fields
ushort htype Hardware type.
ushort ptype Protocol type (e.g., ETYPE_IP)
uchar hlen Hardware address length.
uchar plen Protocol address length.
ushort op Operation (e.g., ARP_REQ)
uchar sha[6] Sender hardware address.
uchar spa[4] Sender protocol address.
uchar tha[6] Target hardware address.
uchar tpa[4] Target protocol address.

◆ udp_hdr_t

struct udp_hdr_t

UDP header.

Data Fields
ushort srce Source port.
ushort dest Destination port.
ushort length Length.
ushort checksum Checksum.

◆ icmp_hdr_t

struct icmp_hdr_t

ICMP header.

Data Fields
uchar type Message type (e.g., ICMP_ECHO_REQ)
uchar code Error code (zero)
ushort checksum Checksum.
ushort ident Conversation identifier.
ushort seq Sequence number.

◆ mac_hdr_t

struct mac_hdr_t

MAC header for ethernet packet.

Data Fields
uchar dest[6] Destination MAC address.
uchar srce[6] Source MAC address.
ushort type Message type, "EtherType" (e.g., ETYPE_IP)

◆ ip_hdr_t

struct ip_hdr_t

IP packet header.

Data Fields
uchar ver_len Version and header length.
uchar DS DSCP/ECN.
ushort length Message length.
ushort ident Identification (for fragment reassembly)
ushort flg_off Flags/fragment offset; SCAMP doesn't support fragments.
uchar TTL Time-to-live.
uchar protocol Protocol (e.g., PROT_UDP)
ushort checksum Checksum.
uchar srce[4] Source IP address.
uchar dest[4] Destination IP address.

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.