|
spinnaker_tools (BMP) latest
SpiNNaker BMP firmware
|
Networking code for BMP LPC1768. More...
Data Structures | |
| struct | arp_pkt_t |
| ARP packet definition. More... | |
| struct | udp_hdr_t |
| UDP header. More... | |
| struct | icmp_hdr_t |
| ICMP header; only ECHO request and reply are supported. More... | |
| struct | mac_hdr_t |
| Ethernet packet header; will be followed by ip_hdr_t or arp_pkt_t. More... | |
| struct | ip_hdr_t |
| IP header; will be followed by udp_hdr_t or icmp_hdr_t. More... | |
| struct | msg_queue_t |
| The type of the message queue. This is a circular buffer. More... | |
Macros | |
| #define | ETHERNET_SIZE_MAX 384 |
| Maximum size of ethernet message. Larger messages are ignored. | |
| #define | ntohs(t) ((((t) & 0x00ff) << 8) | (((t) & 0xff00) >> 8)) |
| Byteswap: network to host short. | |
| #define | htons(t) ((((t) & 0x00ff) << 8) | (((t) & 0xff00) >> 8)) |
| Byteswap: host to network short. | |
| #define | MAC_HDR_SIZE 14 |
| Size of Ethernet header (mac_hdr_t) | |
| #define | IP_HDR_SIZE 20 |
| Size of IP header (ip_hdr_t) | |
| #define | UDP_HDR_SIZE 8 |
| Size of UDP header (udp_hdr_t) | |
| #define | SDP_PAD_SIZE 2 |
| Size of SDP header (sdp_msg_t) | |
| #define | IP_HDR_OFFSET MAC_HDR_SIZE |
| Offset to IP header in Ethernet packet. | |
| #define | IP_DATA_OFFSET (IP_HDR_OFFSET + IP_HDR_SIZE) |
| Offset to IP body in Ethernet packet. | |
| #define | UDP_HDR_OFFSET IP_DATA_OFFSET |
| Offset to UDP header in Ethernet packet. | |
| #define | UDP_DATA_OFFSET (UDP_HDR_OFFSET + UDP_HDR_SIZE) |
| Offset to UDP body in Ethernet packet. | |
| #define | NUM_MSGS 8 |
| The number of messages we have allocated. | |
| #define | MAX_MSG (NUM_MSGS - 1) |
| The maximum message number, for allocation purposes. | |
| #define | MSG_QUEUE_SIZE NUM_MSGS |
| Size of the message queue. | |
Enumerations | |
| enum | ethernet_packet_types { ETYPE_IP = 0x0800 , ETYPE_ARP = 0x0806 } |
| Types of Ethernet packets we understand. More... | |
| enum | internet_protocol_packet_types { PROT_ICMP = 1 , PROT_UDP = 17 } |
| Types of IP packets we understand. More... | |
| enum | arp_opcodes { ARP_REQ = 1 , ARP_REPLY = 2 } |
| ARP operations we know about. More... | |
| enum | icmp_commands { ICMP_ECHO_REPLY = 0 , ICMP_ECHO_REQ = 8 } |
| ICMP operations we know about. More... | |
Functions | |
| void | msg_init (void) |
| Initialise the message queue. | |
| sdp_msg_t * | msg_get (void) |
| "Allocate" a message from the free message pool | |
| static void | msg_free (sdp_msg_t *msg) |
| "Free" a message, returning it to the free message pool | |
| uint32_t | msg_queue_insert (sdp_msg_t *msg) |
| Insert a message in the message queue. | |
| sdp_msg_t * | msg_queue_remove (void) |
| Get a message from the head of the message queue and remove it from the queue. | |
| uint32_t | msg_queue_size (void) |
| How big is the message queue? | |
| static uint32_t | ipsum (const uint8_t *d, uint32_t len, uint32_t sum) |
| Compute a checksum using IP rules. | |
| static void | copy_mac (const uint8_t *restrict f, uint8_t *restrict t) |
| Copy MAC address. | |
| void | copy_ip (const uint8_t *restrict f, uint8_t *restrict t) |
| Copy IP address. | |
| uint32_t | cmp_ip (const uint8_t *a, const uint8_t *b) |
| Compare two IP addresses. | |
| void | iptag_timer (void) |
| IPTag timeout tick. Called from proc_100hz() every 10ms. | |
| uint32_t | iptag_new (void) |
| Allocate a transient IPTag. | |
| uint32_t | transient_tag (uint8_t *ip, uint8_t *mac, uint32_t port, uint32_t timeout) |
| Allocate and initialise a transient IPTag. | |
| void | copy_ip_hdr (uint8_t *dest, uint32_t prot, ip_hdr_t *ip, uint32_t len) |
| Initialise IP header information. | |
| void | copy_udp (uint8_t *buf, uint32_t len, uint32_t dest, uint32_t srce) |
| Initialise UDP header information. | |
| static void | eth_transmit (uint8_t *buf, uint32_t len, uint32_t type, const uint8_t *dest) |
| Send an ethernet packet. | |
| static void | send_arp_pkt (uint8_t *buf, const uint8_t *dest, const uint8_t *tha, const uint8_t *tpa, uint32_t type) |
| Send an ARP packet. | |
| static void | arp_pkt (uint8_t *buf, uint32_t rx_len) |
| Handle a received ARP packet. | |
| static void | icmp_pkt (uint8_t *buf, uint32_t rx_len) |
| Handle a received ICMP packet. | |
| static void | udp_pkt (uint8_t *rx_pkt, uint32_t rx_len) |
| Handle a received UDP packet. | |
| void | eth_receive (void) |
| Receive a packet off the ethernet hardware. | |
| static void | eth_transmit2 (uint8_t *hdr, uint8_t *buf, uint32_t len, uint8_t *dest) |
| Send an ethernet message. | |
| static void | eth_send_msg (uint32_t tag, sdp_msg_t *msg) |
| Send an SDP message over the ethernet port. | |
| static void | swap_sdp_hdr (sdp_msg_t *msg) |
| Swap source and destination in an SDP message header. | |
| static void | return_msg (sdp_msg_t *msg, uint32_t rc) |
| Returns a message to sender, if sender asked for a response. | |
| void | route_msg (sdp_msg_t *msg) |
| Route a message to its destination. | |
| void | arp_lookup (iptag_t *iptag) |
| Request an ARP lookup. | |
| void | eth_putc (uint32_t c) |
| Add character to ethernet-directed output stream. | |
| void | copy_ip_data (void) |
| Copy IP address data from Flash (bmp_flash_ip and spin_flash_ip) | |
Variables | |
| static uint8_t | eth_buf [ETHERNET_SIZE_MAX] |
| Buffer used to mediate with ethernet hardware. | |
| iptag_t | tag_table [TAG_TABLE_SIZE] |
| The table of IPTags. | |
| static sdp_msg_t | msg_bufs [NUM_MSGS] |
| The allocatable message buffers. | |
| static sdp_msg_t * | msg_root |
| Pointer to the next message to allocate. | |
| static uint32_t | msg_count |
| The number of allocated messages. | |
| static uint32_t | msg_max |
| The maximum value of msg_count. | |
| static msg_queue_t | msg_queue |
| The message queue. | |
| static const uint8_t | bc_mac [] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
| Broadcast MAC address. | |
| static const uint8_t | zero_mac [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| Network MAC address. | |
| ip_data_t | spin_ip |
| IP address of the board we manage. | |
| ip_data_t | bmp_ip |
| Our own IP address. | |
| uint32_t | tag_tto = 9 |
| Tag timeout: 2.56s = 10ms * (1 << (9-1)) | |
| static uint8_t | tube_buf [ETHERNET_SIZE_MAX] |
| Accumulates chars to write to host. | |
| static uint32_t | tube_ptr |
| Point in tube_buf to write. | |
Networking code for BMP LPC1768.
| struct arp_pkt_t |
ARP packet definition.
| Data Fields | ||
|---|---|---|
| uint16_t | htype | Hardware address type code. |
| uint16_t | ptype | Protocol address type code. |
| uint8_t | hlen | Hardware address length. |
| uint8_t | plen | Protocol address length. |
| uint16_t | op | Operation code (see arp_opcodes) |
| uint8_t | sha[6] | Source hardware address. |
| uint8_t | spa[4] | Source protocol address. |
| uint8_t | tha[6] | Target hardware address. |
| uint8_t | tpa[4] | Target protocol address. |
| struct udp_hdr_t |
| struct icmp_hdr_t |
ICMP header; only ECHO request and reply are supported.
| Data Fields | ||
|---|---|---|
| uint8_t | type | ICMP message type (icmp_commands) |
| uint8_t | code | ICMP message subtype. |
| uint16_t | checksum | Checksum of ICMP message. |
| uint16_t | ident | Identifier (for ECHO) |
| uint16_t | seq | Sequence number (for ECHO) |
| struct mac_hdr_t |
Ethernet packet header; will be followed by ip_hdr_t or arp_pkt_t.
| Data Fields | ||
|---|---|---|
| uint8_t | dest[6] | Destination MAC address. |
| uint8_t | srce[6] | Source MAC address. |
| uint16_t | type | Packet type (ethernet_packet_types) |
| struct ip_hdr_t |
IP header; will be followed by udp_hdr_t or icmp_hdr_t.
| Data Fields | ||
|---|---|---|
| uint8_t | ver_len | Version and header length. |
| uint8_t | DS | Differentiated service flags. |
| uint16_t | length | Packet length. |
| uint16_t | ident | Packet identifier. |
| uint16_t | flg_off | Flags and fragment offset. |
| uint8_t | TTL | Time-to-live of packet. |
| uint8_t | protocol | Sub-protocol code (internet_protocol_packet_types) |
| uint16_t | checksum | Header checksum. |
| uint8_t | srce[4] | Source IP address. |
| uint8_t | dest[4] | Destination IP address. |
| struct msg_queue_t |
The type of the message queue. This is a circular buffer.
| Data Fields | ||
|---|---|---|
| uint8_t | insert | Where the next message is to be inserted. |
| uint8_t | remove | Where the next message is to be removed. |
| volatile uint8_t | count | Number of messages in the queue. |
| uint8_t | max |
Maximum number of messages in the queue |
| sdp_msg_t * | queue[MSG_QUEUE_SIZE] | The storage for the message queue. |
| enum arp_opcodes |
| enum icmp_commands |
| sdp_msg_t * msg_get | ( | void | ) |
"Allocate" a message from the free message pool
NULL if the pool is empty
|
static |
"Free" a message, returning it to the free message pool
| [in] | msg | The message to free. Must not be used after this call. |
| uint32_t msg_queue_insert | ( | sdp_msg_t * | msg | ) |
Insert a message in the message queue.
| [in] | msg | The message to enqueue |
| sdp_msg_t * msg_queue_remove | ( | void | ) |
Get a message from the head of the message queue and remove it from the queue.
NULL if the queue is empty | uint32_t msg_queue_size | ( | void | ) |
How big is the message queue?
|
static |
Compute a checksum using IP rules.
| [in] | d | The buffer to compute the checksum of |
| [in] | len | The length of buffer in d |
| [in] | sum | Existing checksum value to accumulate to; use 0 for first step |
|
static |
Copy MAC address.
| [in] | f | Where to copy from |
| [out] | t | Where to copy to |
| void copy_ip | ( | const uint8_t *restrict | f, |
| uint8_t *restrict | t | ||
| ) |
Copy IP address.
| [in] | f | Where to copy from |
| [out] | t | Where to copy to |
| uint32_t cmp_ip | ( | const uint8_t * | a, |
| const uint8_t * | b | ||
| ) |
Compare two IP addresses.
| [in] | a | IP address 1 |
| [in] | b | IP address 2 |
| uint32_t iptag_new | ( | void | ) |
Allocate a transient IPTag.
| uint32_t transient_tag | ( | uint8_t * | ip, |
| uint8_t * | mac, | ||
| uint32_t | port, | ||
| uint32_t | timeout | ||
| ) |
Allocate and initialise a transient IPTag.
| ip | Source IP address |
| mac | Sender MAC address (probably gateway) |
| port | Sender UDP port |
| timeout | Timeout associated with IPTag (number of 10ms ticks the tag is to live for) |
| void copy_ip_hdr | ( | uint8_t * | dest, |
| uint32_t | prot, | ||
| ip_hdr_t * | ip, | ||
| uint32_t | len | ||
| ) |
Initialise IP header information.
| [in] | dest | Destination IP address |
| [in] | prot | IP sub-protocol |
| [out] | ip | Buffer holding IP header |
| [in] | len | Length of whole message |
| void copy_udp | ( | uint8_t * | buf, |
| uint32_t | len, | ||
| uint32_t | dest, | ||
| uint32_t | srce | ||
| ) |
Initialise UDP header information.
| [in,out] | buf | Buffer holding whole Ethernet message |
| [in] | len | Length of message payload |
| [in] | dest | Destination UDP port |
| [in] | srce | Source UDP port |
|
static |
Send an ethernet packet.
Writes to the packet header; body must be supplied.
| [in] | buf | The buffer holding the ethernet packet |
| [in] | len | Length of whole message in buf |
| [in] | type | The message type |
| [in] | dest | The destination MAC address |
|
static |
Send an ARP packet.
Writes to the packet header; body must be supplied.
| [in] | buf | The buffer holding the ARP packet, including space for all headers |
| [in] | dest | The destination MAC address |
| [in] | tha | Target hardware address (MAC) |
| [in] | tpa | Target protocol address (IP) |
| [in] | type | ARP operation |
|
static |
Handle a received ARP packet.
| [in] | buf | The received message, including ethernet headers |
| [in] | rx_len | The received length |
|
static |
Handle a received ICMP packet.
| [in] | buf | The received message, including ethernet headers |
| [in] | rx_len | The received length |
|
static |
Handle a received UDP packet.
| [in] | rx_pkt | The received message, including ethernet headers |
| [in] | rx_len | The received length |
| void eth_receive | ( | void | ) |
|
static |
Send an ethernet message.
| [in] | hdr | The ethernet + UDP headers |
| [in] | buf | The buffer holding the message payload |
| [in] | len | Length of payload in buf |
| [in] | dest | The destination MAC address |
|
static |
Send an SDP message over the ethernet port.
| [in] | tag | The index of the IPTag that describes the destination |
| [in] | msg | The SDP message to send |
|
static |
Swap source and destination in an SDP message header.
This reflects the message so it can become its own reply
| [in] | msg | The message to be swapped |
|
static |
Returns a message to sender, if sender asked for a response.
| [in] | msg | The message to return. Ownership of the message is taken! Caller must not use the message after this. |
| [in] | rc | Response code. Non-zero indicates an error (when only header information is used). Zero is an OK response, in which case the payload and length of the message should be set correctly. |
| void route_msg | ( | sdp_msg_t * | msg | ) |
Route a message to its destination.
| [in] | msg | The message to route. Ownership of the message is taken! Caller must not use the message after this. |
| void arp_lookup | ( | iptag_t * | iptag | ) |
Request an ARP lookup.
| [in] | iptag | The IPTag to do the lookup for |
| void eth_putc | ( | uint32_t | c | ) |
Add character to ethernet-directed output stream.
If the buffer is full or at end of line, push the buffer to the configured host machine.
| [in] | c | The character to write |