ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_net.c File Reference

Virtual network peer (Ethernet/ARP/IPv4/ICMP/TCP) for ra8_emulator. More...

#include "board_net.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "board_console.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_net.c:

Go to the source code of this file.

Enumerations

enum  board_net_frame_off_t : uint8_t {
  k_arp_plen_off = 5U ,
  k_arp_spa_off = 14U ,
  k_arp_tha_off = 18U ,
  k_tcp_off_payload = 20U
}
 Offsets into the frames this stub synthesises (RFC 826 / RFC 793). More...
enum  net_console_t : uint32_t { k_net_console_line_cap = 48U }
 Console-tap line buffer capacity for a network packet summary. More...
enum  net_addr_t : uint32_t {
  k_net_peer_ip = 0xC0A80101UL ,
  k_net_fw_ip = 0xC0A8012AUL ,
  k_net_echo_port = 7U ,
  k_net_peer_port = 49152U
}
 Addressing + protocol constants for the peer and the firmware. More...
enum  net_frame_t : uint32_t {
  k_eth_hdr = 14U ,
  k_eth_arp = 0x0806U ,
  k_eth_ipv4 = 0x0800U ,
  k_arp_len = 28U ,
  k_ip_hdr = 20U ,
  k_icmp_hdr = 8U ,
  k_ip_proto_icmp = 1U ,
  k_ip_proto_tcp = 6U ,
  k_mac_len = 6U ,
  k_net_buf = 1600U
}
 Frame offsets / sizes (Ethernet II + ARP + IPv4 + ICMP + TCP). More...
enum  net_proto_t : uint32_t {
  k_byte_mask = 0xFFU ,
  k_u16_mask = 0xFFFFU ,
  k_shift24 = 24U ,
  k_peer_mac_b2 = 0x5EU ,
  k_peer_mac_b4 = 0x53U ,
  k_eth_ethertype_off = 12U ,
  k_arp_plen = 4U ,
  k_arp_tpa_off = 24U ,
  k_ipv4_ver_ihl = 0x45U ,
  k_ip_ident = 0x1234U ,
  k_ip_flag_df = 0x4000U ,
  k_ip_ttl = 64U ,
  k_ip_proto_off = 9U ,
  k_ip_csum_off = 10U ,
  k_ip_src_off = 12U ,
  k_ip_dst_off = 16U ,
  k_ip_ihl_mask = 0x0FU ,
  k_ihl_word = 4U ,
  k_icmp_ident = 0xBEEFU ,
  k_icmp_pat_base = 0x40U ,
  k_tcp_hdr = 20U ,
  k_tcp_payload_max = 64U ,
  k_tcp_off_dataoff = 12U ,
  k_tcp_off_flags = 13U ,
  k_tcp_off_window = 14U ,
  k_tcp_data_off = 0x50U ,
  k_tcp_window = 2048U ,
  k_tcp_isn = 1000U ,
  k_tcp_doff_shift = 4U
}
 Protocol field offsets, masks, and well-known values for the frames board_net builds/parses (Ethernet / ARP / IPv4 / ICMP / TCP). More...
enum  net_state_t : uint8_t {
  k_net_init = 0U ,
  k_net_arp = 1U ,
  k_net_ping = 2U ,
  k_net_syn = 3U ,
  k_net_estab = 4U ,
  k_net_fin = 5U ,
  k_net_done = 6U
}
 Peer state machine: ARP -> ping -> TCP connect / echo / close. More...
enum  net_tcp_flag_t : uint8_t {
  k_tcp_fin = 0x01U ,
  k_tcp_syn = 0x02U ,
  k_tcp_rst = 0x04U ,
  k_tcp_psh = 0x08U ,
  k_tcp_ack = 0x10U
}
 TCP control-bit flags. More...
enum  : uint32_t { k_net_tcp_payload_len = 23U }
 Payload length the threadx_netx_tcp_echo hil.conf asserts. More...
enum  : uint32_t { k_net_qdepth = 8U }

Functions

static RA8_INTERNAL void internal_put16 (uint8_t *p, uint16_t v)
 Store a 16-bit value big-endian (network order) at p.
static RA8_INTERNAL void internal_put32 (uint8_t *p, uint32_t v)
 Store a 32-bit value big-endian at p.
static RA8_INTERNAL uint16_t internal_get16 (const uint8_t *p)
 Read a big-endian 16-bit value from p.
static RA8_INTERNAL uint32_t internal_get32 (const uint8_t *p)
 Read a big-endian 32-bit value from p.
static RA8_INTERNAL uint16_t internal_net_checksum (const uint8_t *d, uint32_t len, uint32_t seed)
 16-bit one's-complement checksum over len bytes at d.
static RA8_INTERNAL void internal_net_queue (const uint8_t *frame, uint32_t len)
 Queue a built frame for the firmware to receive (drops if ring full).
static RA8_INTERNAL void internal_net_eth_hdr (uint8_t *f, const uint8_t *dst, uint16_t ethertype)
 Fill the 14-byte Ethernet header into f.
static RA8_INTERNAL void internal_net_send_arp_request (void)
 Build + queue an ARP request asking who-has the firmware's IP.
static RA8_INTERNAL void internal_net_send_arp_reply (const uint8_t *to_mac, uint32_t to_ip)
 Build + queue an ARP reply giving the peer's MAC to the firmware.
static RA8_INTERNAL void internal_net_ip_hdr (uint8_t *ip, uint8_t proto, uint16_t payload_len)
 Fill a 20-byte IPv4 header (no options) + compute its checksum.
static RA8_INTERNAL void internal_net_send_ping (void)
 Build + queue an ICMP echo request to the firmware.
static RA8_INTERNAL void internal_net_send_tcp (uint8_t flags, const uint8_t *payload, uint16_t payload_len)
 Build + queue a TCP segment to the firmware echo port (flags+payload).
static RA8_INTERNAL void internal_net_send_syn (void)
 Open the TCP connection: send SYN with our initial sequence number.
static RA8_INTERNAL void internal_net_send_data (void)
 Send the test payload to the established echo connection.
static RA8_INTERNAL void internal_net_tcp_on_estab (uint32_t seq, const uint8_t *pdata, uint32_t plen)
 ESTAB state: echo-match the payload, then start our active (FIN) close.
static RA8_INTERNAL void internal_net_rx_tcp (const uint8_t *t, uint32_t len)
 Handle an inbound TCP segment: drive the connect / echo / close FSM.
static RA8_INTERNAL void internal_net_rx_arp (const uint8_t *a, uint32_t len)
 Handle an inbound ARP frame (learn the firmware MAC / answer who-has).
static RA8_INTERNAL void internal_net_rx_icmp (const uint8_t *ic, uint32_t len)
 Handle an inbound ICMP echo reply (count a successful ping).
static RA8_INTERNAL void internal_net_rx_ipv4 (const uint8_t *ip, uint32_t len)
 Handle an inbound IPv4 frame, dispatching by protocol.
void board_net_on_tx (const uint8_t *frame, uint32_t len)
 Hand one frame the firmware transmitted to the peer (ra8_eth_write).
uint32_t board_net_poll_rx (uint8_t *buf, uint32_t max)
 Fetch the next frame the peer wants the firmware to receive.
void board_net_tick (void)
 Advance the peer's state machine one tick (ARP -> ping -> TCP echo).
void board_net_init (bool trace)
 Reset the virtual network peer to its initial state.
static RA8_INTERNAL const char * internal_net_echo_state (void)
 One-word verdict for the TCP echo leg of the run report.
void board_net_report (void)
 Print the end-of-run network summary (link / ARP / ping / TCP).

Variables

static const uint8_t s_peer_mac [k_mac_len]
static bool s_trace
static uint8_t s_state
static uint8_t s_fw_mac [k_mac_len]
 Learned from ARP.
static bool s_fw_mac_known
static uint32_t s_arp_replies
 ARP replies received.
static uint32_t s_pings
 ICMP echo replies received.
static uint32_t s_wait
 Ticks since the last send.
static uint16_t s_ping_seq
 ICMP echo sequence.
static uint32_t s_tx_frames
 Frames the firmware sent.
static uint32_t s_polls
 ra8_eth_read polls served.
static uint32_t s_delivered
 Frames delivered to firmware.
static uint32_t s_tcp_our_seq
 Our next TCP send sequence.
static uint32_t s_tcp_their_seq
 Their next seq (our ack).
static uint32_t s_tcp_echoed
 Echo payload bytes received.
static bool s_tcp_match
 Echo matched what we sent.
static bool s_tcp_need_data
 Payload queued to send post-handshake.
static uint32_t s_tcp_estab_wait
 Ticks since the connection established.
static const uint8_t s_tcp_payload [] = "tcp echo probe payload\n"
 Payload the peer sends to the firmware's TCP echo server.
static uint8_t s_rxq [k_net_qdepth][k_net_buf]
static uint16_t s_rxq_len [k_net_qdepth]
static uint32_t s_rxq_head
static uint32_t s_rxq_tail

Detailed Description

Virtual network peer (Ethernet/ARP/IPv4/ICMP/TCP) for ra8_emulator.

Implements the "other host on the wire" behind the ra8_eth frame seam (see board_net.h). The peer is 192.168.1.1 (MAC 02:00:5E:00:53:01); the firmware is 192.168.1.42. Its state machine resolves the firmware over ARP, pings it (ICMP), then opens a TCP connection to the echo server on port 7, sends a payload, and verifies the echo – proving the NetX networking example runs end-to-end with no hardware. Frames are exchanged as plain byte buffers; main.c marshals them to/from guest memory.

Since
0.1.0

Definition in file board_net.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : uint32_t

Payload length the threadx_netx_tcp_echo hil.conf asserts.

Enumerator
k_net_tcp_payload_len 

sizeof(s_tcp_payload) - 1, pinned.

Definition at line 158 of file board_net.c.

◆ anonymous enum

anonymous enum : uint32_t
Enumerator
k_net_qdepth 

Net qdepth.

Definition at line 169 of file board_net.c.

◆ board_net_frame_off_t

enum board_net_frame_off_t : uint8_t

Offsets into the frames this stub synthesises (RFC 826 / RFC 793).

Enumerator
k_arp_plen_off 

ARP protocol-address-length field offset.

k_arp_spa_off 

ARP sender-protocol-address offset.

k_arp_tha_off 

ARP target-hardware-address offset.

k_tcp_off_payload 

TCP payload offset (no options here).

Definition at line 29 of file board_net.c.

◆ net_addr_t

enum net_addr_t : uint32_t

Addressing + protocol constants for the peer and the firmware.

Enumerator
k_net_peer_ip 

192.168.1.1 (the peer).

k_net_fw_ip 

192.168.1.42 (the firmware).

k_net_echo_port 

Firmware TCP echo server port.

k_net_peer_port 

Peer ephemeral source port.

Definition at line 42 of file board_net.c.

◆ net_console_t

enum net_console_t : uint32_t

Console-tap line buffer capacity for a network packet summary.

Enumerator
k_net_console_line_cap 

Max chars in a "NET tx eth=.." line.

Definition at line 37 of file board_net.c.

◆ net_frame_t

enum net_frame_t : uint32_t

Frame offsets / sizes (Ethernet II + ARP + IPv4 + ICMP + TCP).

Enumerator
k_eth_hdr 

dst[6] src[6] type[2].

k_eth_arp 

ARP ethertype.

k_eth_ipv4 

IPv4 ethertype.

k_arp_len 

ARP payload length.

k_ip_hdr 

IPv4 header (no options).

k_icmp_hdr 

ICMP echo header.

k_ip_proto_icmp 

IPv4 protocol = ICMP.

k_ip_proto_tcp 

IPv4 protocol = TCP.

k_mac_len 

Ethernet address length.

k_net_buf 

Staging buffer size.

Definition at line 50 of file board_net.c.

◆ net_proto_t

enum net_proto_t : uint32_t

Protocol field offsets, masks, and well-known values for the frames board_net builds/parses (Ethernet / ARP / IPv4 / ICMP / TCP).

Enumerator
k_byte_mask 

One octet.

k_u16_mask 

16-bit field.

k_shift24 

Byte-3 position in a 32-bit word.

k_peer_mac_b2 

Peer MAC octet 2 (locally admin).

k_peer_mac_b4 

Peer MAC octet 4.

k_eth_ethertype_off 

EtherType offset in the eth header.

k_arp_plen 

ARP protocol-address length (IPv4).

k_arp_tpa_off 

ARP target-protocol-address offset.

k_ipv4_ver_ihl 

IPv4 version 4, IHL 5.

k_ip_ident 

IPv4 identification (fixed).

k_ip_flag_df 

IPv4 don't-fragment flag.

k_ip_ttl 

IPv4 default TTL.

k_ip_proto_off 

IPv4 protocol-field offset.

k_ip_csum_off 

IPv4 header-checksum offset.

k_ip_src_off 

IPv4 source-address offset.

k_ip_dst_off 

IPv4 destination-address offset.

k_ip_ihl_mask 

IHL / data-offset nibble mask.

k_ihl_word 

IHL/data-offset word size (bytes).

k_icmp_ident 

ICMP echo identifier (fixed).

k_icmp_pat_base 

ICMP payload byte-pattern base.

k_tcp_hdr 

TCP header bytes (no options).

k_tcp_payload_max 

Max TCP payload board_net sends.

k_tcp_off_dataoff 

TCP data-offset byte position.

k_tcp_off_flags 

TCP flags byte position.

k_tcp_off_window 

TCP window field position.

k_tcp_data_off 

TCP data offset = 5 words.

k_tcp_window 

TCP advertised window.

k_tcp_isn 

Deterministic initial seq number.

k_tcp_doff_shift 

TCP data-offset high-nibble shift.

Definition at line 68 of file board_net.c.

◆ net_state_t

enum net_state_t : uint8_t

Peer state machine: ARP -> ping -> TCP connect / echo / close.

Enumerator
k_net_init 

Nothing sent yet.

k_net_arp 

ARP request out; awaiting reply.

k_net_ping 

ICMP echo out; awaiting reply.

k_net_syn 

TCP SYN out; awaiting SYN-ACK.

k_net_estab 

Connected; data out, awaiting echo.

k_net_fin 

FIN out; awaiting close.

k_net_done 

Connection closed.

Definition at line 101 of file board_net.c.

◆ net_tcp_flag_t

enum net_tcp_flag_t : uint8_t

TCP control-bit flags.

Enumerator
k_tcp_fin 

TCP fin.

k_tcp_syn 

TCP syn.

k_tcp_rst 

TCP rst.

k_tcp_psh 

TCP psh.

k_tcp_ack 

TCP ack.

Definition at line 112 of file board_net.c.

Function Documentation

◆ board_net_init()

void board_net_init ( bool trace)

Reset the virtual network peer to its initial state.

Parameters
[in]traceMirror per-frame activity to injected error sink when true.

Reset the virtual network peer to its initial state; this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board net init.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 786 of file board_net.c.

References k_net_init, memset(), s_arp_replies, s_delivered, s_fw_mac, s_fw_mac_known, s_ping_seq, s_pings, s_polls, s_rxq_head, s_rxq_tail, s_state, s_tcp_echoed, s_tcp_estab_wait, s_tcp_match, s_tcp_need_data, s_tcp_our_seq, s_tcp_their_seq, s_trace, s_tx_frames, and s_wait.

Referenced by internal_main_bringup_peripherals(), and warm_reboot().

◆ board_net_on_tx()

void board_net_on_tx ( const uint8_t * frame,
uint32_t len )

Hand one frame the firmware transmitted to the peer (ra8_eth_write).

Parameters
[in]frameEthernet frame bytes (no FCS).
[in]lenFrame length in bytes.

Hand one frame the firmware transmitted to the peer (ra8_eth_write); this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board net on tx.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 710 of file board_net.c.

References board_console_push(), internal_get16(), internal_net_rx_arp(), internal_net_rx_ipv4(), k_board_console_ch_net, k_eth_arp, k_eth_ethertype_off, k_eth_hdr, k_eth_ipv4, k_net_console_line_cap, priv_emu_io_errf(), s_trace, and s_tx_frames.

Referenced by internal_eth_tx_kick_queue().

◆ board_net_poll_rx()

uint32_t board_net_poll_rx ( uint8_t * buf,
uint32_t max )

Fetch the next frame the peer wants the firmware to receive.

Parameters
[out]bufDestination for the frame bytes.
[in]maxCapacity of buf.
Returns
Frame length copied (0 if the peer has nothing queued).

Fetch the next frame the peer wants the firmware to receive; this step is contained within the board net model and uses bounded caller or module-owned storage.

Return values
valueThe operation-specific board net poll rx value.
Precondition
Arguments satisfy the ranges documented for board net poll rx.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 733 of file board_net.c.

References board_console_push(), k_board_console_ch_net, k_net_console_line_cap, k_net_qdepth, memcpy(), s_delivered, s_polls, s_rxq, s_rxq_head, s_rxq_len, and s_rxq_tail.

Referenced by internal_eth_rx_drain_peer().

◆ board_net_report()

void board_net_report ( void )

Print the end-of-run network summary (link / ARP / ping / TCP).

Print the end-of-run network summary (link / arp / ping / tcp); this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board net report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 829 of file board_net.c.

References internal_net_echo_state(), k_net_estab, k_net_init, k_net_syn, priv_emu_io_errf(), s_delivered, s_fw_mac_known, s_pings, s_polls, s_state, s_tcp_echoed, and s_tx_frames.

Referenced by internal_run_print_stop_summary().

◆ board_net_tick()

void board_net_tick ( void )

Advance the peer's state machine one tick (ARP -> ping -> TCP echo).

Advance the peer's state machine one tick (arp -> ping -> tcp echo); this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for board net tick.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

< Net data delay.

< Net retry.

Definition at line 753 of file board_net.c.

References internal_net_send_arp_request(), internal_net_send_data(), internal_net_send_ping(), internal_net_send_syn(), k_net_arp, k_net_estab, k_net_init, k_net_ping, k_net_syn, s_state, s_tcp_estab_wait, s_tcp_need_data, and s_wait.

Referenced by internal_run_loop_tick_inputs().

◆ internal_get16()

RA8_INTERNAL uint16_t internal_get16 ( const uint8_t * p)
static

Read a big-endian 16-bit value from p.

Read a big-endian 16-bit value from p; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]pModule-owned state object processed by the operation.
Returns
The get16 result produced by the board net model.
Return values
valueThe operation-specific get16 value.
Precondition
Arguments satisfy the ranges documented for get16.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 227 of file board_net.c.

References RA8_INTERNAL.

Referenced by board_net_on_tx(), internal_net_rx_arp(), internal_net_rx_ipv4(), and internal_net_rx_tcp().

◆ internal_get32()

RA8_INTERNAL uint32_t internal_get32 ( const uint8_t * p)
static

Read a big-endian 32-bit value from p.

Read a big-endian 32-bit value from p; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]pModule-owned state object processed by the operation.
Returns
The get32 result produced by the board net model.
Return values
valueThe operation-specific get32 value.
Precondition
Arguments satisfy the ranges documented for get32.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 243 of file board_net.c.

References k_shift24, and RA8_INTERNAL.

Referenced by internal_net_rx_arp(), and internal_net_rx_tcp().

◆ internal_net_checksum()

RA8_INTERNAL uint16_t internal_net_checksum ( const uint8_t * d,
uint32_t len,
uint32_t seed )
static

16-bit one's-complement checksum over len bytes at d.

16-bit one's-complement checksum over len bytes at d; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]dD input used by the operation.
[in]lenNumber of payload bytes to process.
[in]seedSeed input used by the operation.
Returns
The net checksum result produced by the board net model.
Return values
valueThe operation-specific net checksum value.
Precondition
Arguments satisfy the ranges documented for net checksum.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 262 of file board_net.c.

References k_u16_mask, and RA8_INTERNAL.

Referenced by internal_net_ip_hdr(), internal_net_send_ping(), and internal_net_send_tcp().

◆ internal_net_echo_state()

RA8_INTERNAL const char * internal_net_echo_state ( void )
static

One-word verdict for the TCP echo leg of the run report.

Returns
"MATCH" when the echo came back byte-identical, "MISMATCH" when bytes came back but differed, "pending" when none came back.
Precondition
The TCP counters reflect the finished run.
Postcondition
No state is modified.

Definition at line 818 of file board_net.c.

References RA8_INTERNAL, s_tcp_echoed, and s_tcp_match.

Referenced by board_net_report().

◆ internal_net_eth_hdr()

RA8_INTERNAL void internal_net_eth_hdr ( uint8_t * f,
const uint8_t * dst,
uint16_t ethertype )
static

Fill the 14-byte Ethernet header into f.

Fill the 14-byte ethernet header into f; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in,out]fF state or storage updated in place by the operation.
[in]dstDestination storage receiving the result.
[in]ethertypeEthertype input used by the operation.
Precondition
Arguments satisfy the ranges documented for net Ethernet hdr.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 309 of file board_net.c.

References internal_put16(), k_eth_ethertype_off, k_mac_len, memcpy(), RA8_INTERNAL, and s_peer_mac.

Referenced by internal_net_send_arp_reply(), internal_net_send_arp_request(), internal_net_send_ping(), and internal_net_send_tcp().

◆ internal_net_ip_hdr()

RA8_INTERNAL void internal_net_ip_hdr ( uint8_t * ip,
uint8_t proto,
uint16_t payload_len )
static

Fill a 20-byte IPv4 header (no options) + compute its checksum.

Fill a 20-byte ipv4 header (no options) + compute its checksum; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in,out]ipIp state or storage updated in place by the operation.
[in]protoProto input used by the operation.
[in]payload_lenBound for the payload data.
Precondition
Arguments satisfy the ranges documented for net ip hdr.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 396 of file board_net.c.

References internal_net_checksum(), internal_put16(), internal_put32(), k_ip_csum_off, k_ip_dst_off, k_ip_flag_df, k_ip_hdr, k_ip_ident, k_ip_proto_off, k_ip_src_off, k_ip_ttl, k_ipv4_ver_ihl, k_net_fw_ip, k_net_peer_ip, memset(), and RA8_INTERNAL.

Referenced by internal_net_send_ping(), and internal_net_send_tcp().

◆ internal_net_queue()

RA8_INTERNAL void internal_net_queue ( const uint8_t * frame,
uint32_t len )
static

Queue a built frame for the firmware to receive (drops if ring full).

Queue a built frame for the firmware to receive (drops if ring full); this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]frameFrame input used by the operation.
[in]lenNumber of payload bytes to process.
Precondition
Arguments satisfy the ranges documented for net queue.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 287 of file board_net.c.

References k_net_buf, k_net_qdepth, memcpy(), RA8_INTERNAL, s_rxq, s_rxq_head, s_rxq_len, and s_rxq_tail.

Referenced by internal_net_send_arp_reply(), internal_net_send_arp_request(), internal_net_send_ping(), and internal_net_send_tcp().

◆ internal_net_rx_arp()

RA8_INTERNAL void internal_net_rx_arp ( const uint8_t * a,
uint32_t len )
static

Handle an inbound ARP frame (learn the firmware MAC / answer who-has).

Handle an inbound arp frame (learn the firmware mac / answer who-has); this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]aA input used by the operation.
[in]lenNumber of payload bytes to process.
Precondition
Arguments satisfy the ranges documented for net rx arp.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 623 of file board_net.c.

References internal_get16(), internal_get32(), internal_net_send_arp_reply(), internal_net_send_ping(), k_arp_len, k_mac_len, k_net_arp, k_net_fw_ip, k_net_peer_ip, k_net_ping, memcpy(), RA8_INTERNAL, s_arp_replies, s_fw_mac, s_fw_mac_known, s_state, and s_wait.

Referenced by board_net_on_tx().

◆ internal_net_rx_icmp()

RA8_INTERNAL void internal_net_rx_icmp ( const uint8_t * ic,
uint32_t len )
static

Handle an inbound ICMP echo reply (count a successful ping).

Handle an inbound icmp echo reply (count a successful ping); this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]icIc input used by the operation.
[in]lenNumber of payload bytes to process.
Precondition
Arguments satisfy the ranges documented for net rx icmp.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 658 of file board_net.c.

References internal_net_send_syn(), k_icmp_hdr, k_net_ping, k_net_syn, priv_emu_io_errf(), RA8_INTERNAL, s_pings, s_state, s_trace, and s_wait.

Referenced by internal_net_rx_ipv4().

◆ internal_net_rx_ipv4()

RA8_INTERNAL void internal_net_rx_ipv4 ( const uint8_t * ip,
uint32_t len )
static

Handle an inbound IPv4 frame, dispatching by protocol.

Handle an inbound ipv4 frame, dispatching by protocol; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]ipIp input used by the operation.
[in]lenNumber of payload bytes to process.
Precondition
Arguments satisfy the ranges documented for net rx ipv4.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 684 of file board_net.c.

References internal_get16(), internal_net_rx_icmp(), internal_net_rx_tcp(), k_ihl_word, k_ip_hdr, k_ip_ihl_mask, k_ip_proto_icmp, k_ip_proto_tcp, and RA8_INTERNAL.

Referenced by board_net_on_tx().

◆ internal_net_rx_tcp()

RA8_INTERNAL void internal_net_rx_tcp ( const uint8_t * t,
uint32_t len )
static

Handle an inbound TCP segment: drive the connect / echo / close FSM.

Handle an inbound tcp segment: drive the connect / echo / close fsm; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]tT input used by the operation.
[in]lenNumber of payload bytes to process.
Precondition
Arguments satisfy the ranges documented for net rx tcp.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 556 of file board_net.c.

References internal_get16(), internal_get32(), internal_net_send_tcp(), internal_net_tcp_on_estab(), k_ihl_word, k_ip_ihl_mask, k_net_done, k_net_echo_port, k_net_estab, k_net_fin, k_net_peer_port, k_net_syn, k_tcp_ack, k_tcp_doff_shift, k_tcp_fin, k_tcp_hdr, k_tcp_off_dataoff, k_tcp_syn, priv_emu_io_errf(), RA8_INTERNAL, s_state, s_tcp_estab_wait, s_tcp_need_data, s_tcp_our_seq, s_tcp_their_seq, and s_trace.

Referenced by internal_net_rx_ipv4().

◆ internal_net_send_arp_reply()

RA8_INTERNAL void internal_net_send_arp_reply ( const uint8_t * to_mac,
uint32_t to_ip )
static

Build + queue an ARP reply giving the peer's MAC to the firmware.

Build + queue an arp reply giving the peer's mac to the firmware; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]to_macTo mac input used by the operation.
[in]to_ipTo ip input used by the operation.
Precondition
Arguments satisfy the ranges documented for net send arp reply.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 362 of file board_net.c.

References internal_net_eth_hdr(), internal_net_queue(), internal_put16(), internal_put32(), k_arp_len, k_arp_plen, k_arp_plen_off, k_arp_spa_off, k_arp_tha_off, k_arp_tpa_off, k_eth_arp, k_eth_hdr, k_eth_ipv4, k_mac_len, k_net_peer_ip, memcpy(), memset(), RA8_INTERNAL, and s_peer_mac.

Referenced by internal_net_rx_arp().

◆ internal_net_send_arp_request()

RA8_INTERNAL void internal_net_send_arp_request ( void )
static

Build + queue an ARP request asking who-has the firmware's IP.

Build + queue an arp request asking who-has the firmware's ip; this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for net send arp request.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 329 of file board_net.c.

References internal_net_eth_hdr(), internal_net_queue(), internal_put16(), internal_put32(), k_arp_len, k_arp_plen, k_arp_plen_off, k_arp_spa_off, k_arp_tpa_off, k_byte_mask, k_eth_arp, k_eth_hdr, k_eth_ipv4, k_mac_len, k_net_fw_ip, k_net_peer_ip, memcpy(), memset(), RA8_INTERNAL, and s_peer_mac.

Referenced by board_net_tick().

◆ internal_net_send_data()

RA8_INTERNAL void internal_net_send_data ( void )
static

Send the test payload to the established echo connection.

Send the test payload to the established echo connection; this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for net send data.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 512 of file board_net.c.

References internal_net_send_tcp(), k_tcp_ack, k_tcp_psh, RA8_INTERNAL, s_tcp_our_seq, and s_tcp_payload.

Referenced by board_net_tick().

◆ internal_net_send_ping()

RA8_INTERNAL void internal_net_send_ping ( void )
static

Build + queue an ICMP echo request to the firmware.

Build + queue an icmp echo request to the firmware; this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for net send ping.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 418 of file board_net.c.

References internal_net_checksum(), internal_net_eth_hdr(), internal_net_ip_hdr(), internal_net_queue(), internal_put16(), k_eth_hdr, k_eth_ipv4, k_icmp_hdr, k_icmp_ident, k_icmp_pat_base, k_ip_hdr, k_ip_proto_icmp, memset(), RA8_INTERNAL, s_fw_mac, s_fw_mac_known, and s_ping_seq.

Referenced by board_net_tick(), and internal_net_rx_arp().

◆ internal_net_send_syn()

RA8_INTERNAL void internal_net_send_syn ( void )
static

Open the TCP connection: send SYN with our initial sequence number.

Open the tcp connection: send syn with our initial sequence number; this step is contained within the board net model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for net send syn.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 498 of file board_net.c.

References internal_net_send_tcp(), k_tcp_isn, k_tcp_syn, RA8_INTERNAL, and s_tcp_our_seq.

Referenced by board_net_tick(), and internal_net_rx_icmp().

◆ internal_net_send_tcp()

RA8_INTERNAL void internal_net_send_tcp ( uint8_t flags,
const uint8_t * payload,
uint16_t payload_len )
static

Build + queue a TCP segment to the firmware echo port (flags+payload).

Build + queue a tcp segment to the firmware echo port (flags+payload); this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]flagsFlags input used by the operation.
[in]payloadPayload input used by the operation.
[in]payload_lenBound for the payload data.
Precondition
Arguments satisfy the ranges documented for net send tcp.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 457 of file board_net.c.

References internal_net_checksum(), internal_net_eth_hdr(), internal_net_ip_hdr(), internal_net_queue(), internal_put16(), internal_put32(), k_eth_hdr, k_eth_ipv4, k_ip_hdr, k_ip_proto_tcp, k_net_echo_port, k_net_fw_ip, k_net_peer_ip, k_net_peer_port, k_tcp_data_off, k_tcp_hdr, k_tcp_off_dataoff, k_tcp_off_flags, k_tcp_off_payload, k_tcp_off_window, k_tcp_payload_max, k_tcp_window, k_u16_mask, memcpy(), memset(), s_fw_mac, s_fw_mac_known, s_tcp_our_seq, and s_tcp_their_seq.

Referenced by internal_net_rx_tcp(), internal_net_send_data(), internal_net_send_syn(), and internal_net_tcp_on_estab().

◆ internal_net_tcp_on_estab()

RA8_INTERNAL void internal_net_tcp_on_estab ( uint32_t seq,
const uint8_t * pdata,
uint32_t plen )
static

ESTAB state: echo-match the payload, then start our active (FIN) close.

Estab state: echo-match the payload, then start our active (fin) close; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in]seqSeq input used by the operation.
[in]pdataPdata input used by the operation.
[in]plenPlen input used by the operation.
Precondition
Arguments satisfy the ranges documented for net tcp on estab.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 531 of file board_net.c.

References internal_net_send_tcp(), k_net_fin, k_tcp_ack, k_tcp_fin, memcmp(), priv_emu_io_errf(), s_state, s_tcp_echoed, s_tcp_match, s_tcp_our_seq, s_tcp_payload, s_tcp_their_seq, and s_trace.

Referenced by internal_net_rx_tcp().

◆ internal_put16()

RA8_INTERNAL void internal_put16 ( uint8_t * p,
uint16_t v )
static

Store a 16-bit value big-endian (network order) at p.

Store a 16-bit value big-endian (network order) at p; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in,out]pModule-owned state object processed by the operation.
[in]vRegister or payload value processed by the operation.
Precondition
Arguments satisfy the ranges documented for put16.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 192 of file board_net.c.

References k_byte_mask, and RA8_INTERNAL.

Referenced by internal_net_eth_hdr(), internal_net_ip_hdr(), internal_net_send_arp_reply(), internal_net_send_arp_request(), internal_net_send_ping(), and internal_net_send_tcp().

◆ internal_put32()

RA8_INTERNAL void internal_put32 ( uint8_t * p,
uint32_t v )
static

Store a 32-bit value big-endian at p.

Store a 32-bit value big-endian at p; this step is contained within the board net model and uses bounded caller or module-owned storage.

Parameters
[in,out]pModule-owned state object processed by the operation.
[in]vRegister or payload value processed by the operation.
Precondition
Arguments satisfy the ranges documented for put32.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board net model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 208 of file board_net.c.

References k_byte_mask, k_shift24, and RA8_INTERNAL.

Referenced by internal_net_ip_hdr(), internal_net_send_arp_reply(), internal_net_send_arp_request(), and internal_net_send_tcp().

Variable Documentation

◆ s_arp_replies

uint32_t s_arp_replies
static

ARP replies received.

Definition at line 127 of file board_net.c.

Referenced by board_net_init(), and internal_net_rx_arp().

◆ s_delivered

uint32_t s_delivered
static

Frames delivered to firmware.

Definition at line 133 of file board_net.c.

Referenced by board_net_init(), board_net_poll_rx(), and board_net_report().

◆ s_fw_mac

uint8_t s_fw_mac[k_mac_len]
static

Learned from ARP.

Definition at line 125 of file board_net.c.

Referenced by board_net_init(), internal_net_rx_arp(), internal_net_send_ping(), and internal_net_send_tcp().

◆ s_fw_mac_known

bool s_fw_mac_known
static

◆ s_peer_mac

const uint8_t s_peer_mac[k_mac_len]
static
Initial value:
=
{0x02U, 0x00U, (uint8_t)k_peer_mac_b2, 0x00U, (uint8_t)k_peer_mac_b4, 0x01U}
@ k_peer_mac_b4
Peer MAC octet 4.
Definition board_net.c:73
@ k_peer_mac_b2
Peer MAC octet 2 (locally admin).
Definition board_net.c:72

Definition at line 120 of file board_net.c.

Referenced by internal_net_eth_hdr(), internal_net_send_arp_reply(), and internal_net_send_arp_request().

◆ s_ping_seq

uint16_t s_ping_seq
static

ICMP echo sequence.

Definition at line 130 of file board_net.c.

Referenced by board_net_init(), and internal_net_send_ping().

◆ s_pings

uint32_t s_pings
static

ICMP echo replies received.

Definition at line 128 of file board_net.c.

Referenced by board_net_init(), board_net_report(), and internal_net_rx_icmp().

◆ s_polls

uint32_t s_polls
static

ra8_eth_read polls served.

Definition at line 132 of file board_net.c.

Referenced by board_net_init(), board_net_poll_rx(), and board_net_report().

◆ s_rxq

uint8_t s_rxq[k_net_qdepth][k_net_buf]
static

Definition at line 172 of file board_net.c.

Referenced by board_net_poll_rx(), and internal_net_queue().

◆ s_rxq_head

uint32_t s_rxq_head
static

Definition at line 174 of file board_net.c.

Referenced by board_net_init(), board_net_poll_rx(), and internal_net_queue().

◆ s_rxq_len

uint16_t s_rxq_len[k_net_qdepth]
static

Definition at line 173 of file board_net.c.

Referenced by board_net_poll_rx(), and internal_net_queue().

◆ s_rxq_tail

uint32_t s_rxq_tail
static

Definition at line 175 of file board_net.c.

Referenced by board_net_init(), board_net_poll_rx(), and internal_net_queue().

◆ s_state

uint8_t s_state
static

Definition at line 124 of file board_net.c.

◆ s_tcp_echoed

uint32_t s_tcp_echoed
static

Echo payload bytes received.

Definition at line 136 of file board_net.c.

Referenced by board_net_init(), board_net_report(), internal_net_echo_state(), and internal_net_tcp_on_estab().

◆ s_tcp_estab_wait

uint32_t s_tcp_estab_wait
static

Ticks since the connection established.

Definition at line 139 of file board_net.c.

Referenced by board_net_init(), board_net_tick(), and internal_net_rx_tcp().

◆ s_tcp_match

bool s_tcp_match
static

Echo matched what we sent.

Definition at line 137 of file board_net.c.

Referenced by board_net_init(), internal_net_echo_state(), and internal_net_tcp_on_estab().

◆ s_tcp_need_data

bool s_tcp_need_data
static

Payload queued to send post-handshake.

Definition at line 138 of file board_net.c.

Referenced by board_net_init(), board_net_tick(), and internal_net_rx_tcp().

◆ s_tcp_our_seq

uint32_t s_tcp_our_seq
static

◆ s_tcp_payload

const uint8_t s_tcp_payload[] = "tcp echo probe payload\n"
static

Payload the peer sends to the firmware's TCP echo server.

Its LENGTH is part of the EIL contract, not just an implementation detail: threadx_netx_tcp_echo echoes it and logs "[netx] echoed N bytes", and that exact line is the HIL_EXPECT its hil.conf asserts. So this string must not carry anything that gets renamed. It used to read "hello from board_sim\n" (21 bytes); the board_sim -> ra8_emulator rename silently made it 24 and broke that assertion, which nothing noticed because the app was parked outside the EIL run set at the time (#499). Hence a name-free literal and the static_assert below – change the text freely, but a change in length has to be made deliberately and mirrored in the hil.conf.

Definition at line 155 of file board_net.c.

Referenced by internal_net_send_data(), and internal_net_tcp_on_estab().

◆ s_tcp_their_seq

uint32_t s_tcp_their_seq
static

Their next seq (our ack).

Definition at line 135 of file board_net.c.

Referenced by board_net_init(), internal_net_rx_tcp(), internal_net_send_tcp(), and internal_net_tcp_on_estab().

◆ s_trace

bool s_trace
static

Definition at line 123 of file board_net.c.

◆ s_tx_frames

uint32_t s_tx_frames
static

Frames the firmware sent.

Definition at line 131 of file board_net.c.

Referenced by board_net_init(), board_net_on_tx(), and board_net_report().

◆ s_wait

uint32_t s_wait
static

Ticks since the last send.

Definition at line 129 of file board_net.c.

Referenced by board_net_init(), board_net_tick(), internal_net_rx_arp(), and internal_net_rx_icmp().