spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
spinn_net.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10
11/*
12 * Copyright (c) 2009 The University of Manchester
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * https://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26
27#ifndef SPINN_NET_H
28#define SPINN_NET_H
29
31#define MAC_HDR_SIZE 14
33#define IP_HDR_SIZE 20
35#define UDP_HDR_SIZE 8
37#define SDP_PAD_SIZE 2
38
40#define IP_HDR_OFFSET MAC_HDR_SIZE
42#define IP_DATA_OFFSET (IP_HDR_OFFSET + IP_HDR_SIZE)
43
45#define UDP_HDR_OFFSET IP_DATA_OFFSET
47#define UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_SIZE)
48
49#define ETYPE_IP 0x0800
50#define ETYPE_ARP 0x0806
51
52#define PROT_ICMP 1
53#define PROT_UDP 17
54
55#define ARP_REQ 1
56#define ARP_REPLY 2
57
58#define ICMP_ECHO_REPLY 0
59#define ICMP_ECHO_REQ 8
60
62typedef struct {
68 uchar sha[6];
69 uchar spa[4];
70 uchar tha[6];
71 uchar tpa[4];
72} arp_pkt_t;
73
81
90
92typedef struct mac_hdr_t {
96} mac_hdr_t;
97
111
113extern const uchar bc_mac[];
115extern const uchar zero_mac[];
116
119void eth_init(uchar *mac);
120
126uint ipsum(uchar *d, uint len, uint sum);
127
131void copy_mac(const uchar *f, uchar *t);
132
136void copy_ip(const uchar *f, uchar *t);
137
142uint cmp_ip(const uchar *a, const uchar *b);
143
150void copy_ip_hdr(uchar *dest, uint prot, ip_hdr_t *ip, uint len);
151
158void eth_transmit(uchar *buf, uint len, uint type, const uchar *dest);
159
165void eth_transmit2(uchar *hdr, uchar *buf, uint hdr_len, uint buf_len);
166
174void send_arp_pkt(uchar *buf, const uchar *dest,
175 const uchar *tha, const uchar *tpa, uint type);
176
181void arp_lookup(iptag_t *iptag);
182
187void arp_pkt(uchar *rx_pkt, uint rx_len, uint tag_table_size);
188
192void arp_add(uchar *mac, uchar *ip);
193
197void icmp_pkt(uchar *rx_pkt, uint rx_len);
198
205void copy_udp(uchar *buf, uint len, uint dest, uint srce);
206
207#endif
static int sum
Sum to make moving average easy.
Definition scamp-isr.c:166
IPTAG entry (32 bytes)
Definition scamp.h:376
uchar DS
DSCP/ECN.
Definition spinn_net.h:101
void send_arp_pkt(uchar *buf, const uchar *dest, const uchar *tha, const uchar *tpa, uint type)
Send an ARP packet.
Definition spinn_net.c:228
ushort length
Message length.
Definition spinn_net.h:102
ushort flg_off
Flags/fragment offset; SCAMP doesn't support fragments.
Definition spinn_net.h:104
void eth_transmit(uchar *buf, uint len, uint type, const uchar *dest)
Transmit ethernet packet.
Definition spinn_net.c:170
void arp_lookup(iptag_t *iptag)
Initiate ARP lookup if required. Lookup might be immediate (out of cache) or require network traffic.
Definition spinn_net.c:249
void arp_pkt(uchar *rx_pkt, uint rx_len, uint tag_table_size)
ARP packet received handler.
Definition spinn_net.c:281
uchar TTL
Time-to-live.
Definition spinn_net.h:105
ushort seq
Sequence number.
Definition spinn_net.h:88
uchar srce[6]
Source MAC address.
Definition spinn_net.h:94
void copy_mac(const uchar *f, uchar *t)
Copy MAC address.
Definition spinn_net.c:125
const uchar zero_mac[]
Zero MAC address.
Definition spinn_net.c:42
uchar ver_len
Version and header length.
Definition spinn_net.h:100
void icmp_pkt(uchar *rx_pkt, uint rx_len)
ICMP packet received handler.
Definition spinn_net.c:323
ushort checksum
Checksum.
Definition spinn_net.h:86
ushort htype
Hardware type.
Definition spinn_net.h:63
ushort ident
Conversation identifier.
Definition spinn_net.h:87
uchar plen
Protocol address length.
Definition spinn_net.h:66
uchar protocol
Protocol (e.g., PROT_UDP)
Definition spinn_net.h:106
ushort ptype
Protocol type (e.g., ETYPE_IP)
Definition spinn_net.h:64
void copy_ip_hdr(uchar *dest, uint prot, ip_hdr_t *ip, uint len)
Initialise IP header.
Definition spinn_net.c:152
ushort dest
Destination port.
Definition spinn_net.h:77
void copy_ip(const uchar *f, uchar *t)
Copy IP address.
Definition spinn_net.c:135
uint cmp_ip(const uchar *a, const uchar *b)
Compare IP addresses.
Definition spinn_net.c:144
void copy_udp(uchar *buf, uint len, uint dest, uint srce)
Initialise UDP packet header.
Definition spinn_net.c:364
void eth_init(uchar *mac)
Initialise the ethernet subsystem.
Definition spinn_net.c:91
void arp_add(uchar *mac, uchar *ip)
Add a MAC/IP address binding to our ARP cache.
Definition spinn_net.c:313
ushort type
Message type, "EtherType" (e.g., ETYPE_IP)
Definition spinn_net.h:95
ushort checksum
Checksum.
Definition spinn_net.h:107
uchar hlen
Hardware address length.
Definition spinn_net.h:65
uchar code
Error code (zero)
Definition spinn_net.h:85
ushort checksum
Checksum.
Definition spinn_net.h:79
ushort srce
Source port.
Definition spinn_net.h:76
uint ipsum(uchar *d, uint len, uint sum)
Compute an IP checksum.
Definition spinn_net.c:105
ushort length
Length.
Definition spinn_net.h:78
const uchar bc_mac[]
Broadcast MAC address.
Definition spinn_net.c:41
void eth_transmit2(uchar *hdr, uchar *buf, uint hdr_len, uint buf_len)
Transmit ethernet packet.
Definition spinn_net.c:201
ushort ident
Identification (for fragment reassembly)
Definition spinn_net.h:103
uchar dest[6]
Destination MAC address.
Definition spinn_net.h:93
uchar type
Message type (e.g., ICMP_ECHO_REQ)
Definition spinn_net.h:84
ushort op
Operation (e.g., ARP_REQ)
Definition spinn_net.h:67
ARP packet format.
Definition spinn_net.h:62
ICMP header.
Definition spinn_net.h:83
IP packet header.
Definition spinn_net.h:99
MAC header for ethernet packet.
Definition spinn_net.h:92
UDP header.
Definition spinn_net.h:75
unsigned char uchar
Unsigned integer - 8 bits.
Definition spinnaker.h:37
unsigned int uint
Unsigned integer - 32 bits.
Definition spinnaker.h:39
unsigned short ushort
Unsigned integer - 16 bits.
Definition spinnaker.h:38