29typedef enum : uint8_t {
37typedef enum : uint32_t {
42typedef enum : uint32_t {
50typedef enum : uint32_t {
68typedef enum : uint32_t {
101typedef enum : uint8_t {
112typedef enum : uint8_t {
162 "EIL contract: threadx_netx_tcp_echo's hil.conf HIL_EXPECT names "
163 "this byte count -- update examples/ek_ra8d2/hw_validated/hil/"
164 "threadx_netx_tcp_echo/hil.conf in the same change");
194 p[0] = (uint8_t)(v >> 8);
210 p[0] = (uint8_t)(v >> (uint32_t)
k_shift24);
211 p[1] = (uint8_t)((v >> 16) & (uint32_t)
k_byte_mask);
212 p[2] = (uint8_t)((v >> 8) & (uint32_t)
k_byte_mask);
229 return (uint16_t)(((uint16_t)p[0] << 8) | (uint16_t)p[1]);
245 return ((uint32_t)p[0] << (uint32_t)
k_shift24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) |
265 for (uint32_t i = 0U; (i + 1U) < len; i += 2U) {
266 sum += ((uint32_t)d[i] << 8) | (uint32_t)d[i + 1U];
268 if ((len & 1U) != 0U) {
269 sum += (uint32_t)d[len - 1U] << 8;
271 while ((sum >> 16) != 0U) {
272 sum = (sum & (uint32_t)
k_u16_mask) + (sum >> 16);
274 return (uint16_t)(~sum & (uint32_t)
k_u16_mask);
338 (void)
memset(f, 0,
sizeof(f));
365 (void)
memset(f, 0,
sizeof(f));
424 (void)
memset(f, 0,
sizeof(f));
426 const uint16_t icmp_len = (uint16_t)(
k_icmp_hdr + 16U);
433 for (uint32_t i = 0U; i < 16U; i++) {
463 const uint16_t tcp_len = (uint16_t)((uint16_t)
k_tcp_hdr + payload_len);
464 if (((uint32_t)
k_eth_hdr + (uint32_t)
k_ip_hdr + (uint32_t)tcp_len) >
sizeof(f)) {
467 (void)
memset(f, 0,
sizeof(f));
478 if (payload_len > 0U) {
482 const uint32_t pseudo =
566 const uint8_t flags = t[13];
567 const uint32_t doff =
570 if ((doff < (uint32_t)
k_tcp_hdr) || (doff > len)) {
573 const uint32_t plen = len - doff;
574 const uint8_t* pdata = &t[doff];
576 (void)
priv_emu_io_errf(
" [net] RX TCP flags=0x%02X seq=%u ack=%u plen=%u (state %u)\n",
660 if ((len >= (uint32_t)
k_icmp_hdr) && (ic[0] == 0U)) {
665 " [net] ICMP echo reply from 192.168.1.42 -- ping ok; opening TCP\n");
690 if ((ihl < (uint32_t)
k_ip_hdr) || (ihl > len)) {
697 uint32_t actual = len;
699 if (((uint32_t)ip_total >= ihl) && ((uint32_t)ip_total <= len)) {
700 actual = (uint32_t)ip_total;
702 const uint8_t proto = ip[9];
724 (void)snprintf(ln,
sizeof(ln),
"NET tx eth=0x%04X %uB", (
unsigned)ethertype, (
unsigned)len);
728 }
else if (ethertype == (uint16_t)
k_eth_ipv4) {
748 (void)snprintf(ln,
sizeof(ln),
"NET rx %uB (#%u)", (
unsigned)n, (
unsigned)
s_delivered);
763 enum : uint32_t { k_net_data_delay = 800U };
773 enum : uint32_t { k_net_retry = 2000U };
774 if (
s_wait > k_net_retry) {
834 (void)
priv_emu_io_errf(
" NET peer : 192.168.1.1 <-> 192.168.1.42 ARP %s ping %s (%u)\n",
838 (void)
priv_emu_io_errf(
" NET activity : fw TX %u frame(s), RX polls %u, delivered %u\n",
Multi-channel console log store backing the board view's tabbed console.
void board_console_push(board_console_ch_t ch, const char *line)
Append one completed line to a channel ring and the ALL ring.
@ k_board_console_ch_net
Ethernet / IPv4 / TCP packet summaries.
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 uint16_t s_ping_seq
ICMP echo sequence.
static uint32_t s_wait
Ticks since the last send.
static uint8_t s_fw_mac[k_mac_len]
Learned from ARP.
static uint32_t s_arp_replies
ARP replies received.
static uint32_t s_delivered
Frames delivered to 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 uint8_t s_rxq[k_net_qdepth][k_net_buf]
static uint32_t s_tcp_estab_wait
Ticks since the connection established.
static uint32_t s_rxq_tail
static RA8_INTERNAL void internal_net_send_ping(void)
Build + queue an ICMP echo request to the firmware.
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_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 uint32_t s_polls
ra8_eth_read polls served.
net_state_t
Peer state machine: ARP -> ping -> TCP connect / echo / close.
@ k_net_init
Nothing sent yet.
@ k_net_fin
FIN out; awaiting close.
@ k_net_estab
Connected; data out, awaiting echo.
@ k_net_syn
TCP SYN out; awaiting SYN-ACK.
@ k_net_done
Connection closed.
@ k_net_arp
ARP request out; awaiting reply.
@ k_net_ping
ICMP echo out; awaiting reply.
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.
net_proto_t
Protocol field offsets, masks, and well-known values for the frames board_net builds/parses (Ethernet...
@ k_tcp_window
TCP advertised window.
@ k_ip_dst_off
IPv4 destination-address offset.
@ k_ip_ihl_mask
IHL / data-offset nibble mask.
@ k_ip_src_off
IPv4 source-address offset.
@ k_peer_mac_b4
Peer MAC octet 4.
@ k_arp_tpa_off
ARP target-protocol-address offset.
@ k_ipv4_ver_ihl
IPv4 version 4, IHL 5.
@ k_tcp_isn
Deterministic initial seq number.
@ k_icmp_ident
ICMP echo identifier (fixed).
@ k_peer_mac_b2
Peer MAC octet 2 (locally admin).
@ k_ihl_word
IHL/data-offset word size (bytes).
@ k_tcp_off_window
TCP window field position.
@ k_ip_ident
IPv4 identification (fixed).
@ k_ip_csum_off
IPv4 header-checksum offset.
@ k_tcp_data_off
TCP data offset = 5 words.
@ k_tcp_off_flags
TCP flags byte position.
@ k_shift24
Byte-3 position in a 32-bit word.
@ k_ip_proto_off
IPv4 protocol-field offset.
@ k_ip_flag_df
IPv4 don't-fragment flag.
@ k_arp_plen
ARP protocol-address length (IPv4).
@ k_tcp_doff_shift
TCP data-offset high-nibble shift.
@ k_u16_mask
16-bit field.
@ 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_eth_ethertype_off
EtherType offset in the eth header.
@ k_icmp_pat_base
ICMP payload byte-pattern base.
@ k_ip_ttl
IPv4 default TTL.
void board_net_report(void)
Print the end-of-run network summary (link / ARP / ping / TCP).
void board_net_init(bool trace)
Reset the virtual network peer to its initial state.
static uint16_t s_rxq_len[k_net_qdepth]
static RA8_INTERNAL uint32_t internal_get32(const uint8_t *p)
Read a big-endian 32-bit value from p.
static const uint8_t s_tcp_payload[]
Payload the peer sends to the firmware's TCP echo server.
static uint32_t s_pings
ICMP echo replies received.
static const uint8_t s_peer_mac[k_mac_len]
static RA8_INTERNAL uint16_t internal_get16(const uint8_t *p)
Read a big-endian 16-bit value from p.
uint32_t board_net_poll_rx(uint8_t *buf, uint32_t max)
Fetch the next frame the peer wants the firmware to receive.
static uint32_t s_tcp_our_seq
Our next TCP send sequence.
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 uint32_t s_tcp_echoed
Echo payload bytes received.
static RA8_INTERNAL void internal_net_rx_ipv4(const uint8_t *ip, uint32_t len)
Handle an inbound IPv4 frame, dispatching by protocol.
board_net_frame_off_t
Offsets into the frames this stub synthesises (RFC 826 / RFC 793).
@ k_arp_tha_off
ARP target-hardware-address offset.
@ k_tcp_off_payload
TCP payload offset (no options here).
@ k_arp_plen_off
ARP protocol-address-length field offset.
@ k_arp_spa_off
ARP sender-protocol-address offset.
net_frame_t
Frame offsets / sizes (Ethernet II + ARP + IPv4 + ICMP + TCP).
@ k_icmp_hdr
ICMP echo header.
@ k_eth_hdr
dst[6] src[6] type[2].
@ k_arp_len
ARP payload length.
@ k_net_buf
Staging buffer size.
@ k_ip_proto_tcp
IPv4 protocol = TCP.
@ k_ip_hdr
IPv4 header (no options).
@ k_ip_proto_icmp
IPv4 protocol = ICMP.
@ k_eth_ipv4
IPv4 ethertype.
@ k_mac_len
Ethernet address length.
@ k_eth_arp
ARP ethertype.
net_tcp_flag_t
TCP control-bit flags.
@ k_net_qdepth
Net qdepth.
@ k_net_tcp_payload_len
sizeof(s_tcp_payload) - 1, pinned.
static bool s_tcp_need_data
Payload queued to send post-handshake.
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 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.
void board_net_on_tx(const uint8_t *frame, uint32_t len)
Hand one frame the firmware transmitted to the peer (ra8_eth_write).
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 uint32_t s_rxq_head
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_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 uint32_t s_tx_frames
Frames the firmware sent.
net_addr_t
Addressing + protocol constants for the peer and the firmware.
@ k_net_echo_port
Firmware TCP echo server port.
@ k_net_peer_ip
192.168.1.1 (the peer).
@ k_net_peer_port
Peer ephemeral source port.
@ k_net_fw_ip
192.168.1.42 (the firmware).
static uint32_t s_tcp_their_seq
Their next seq (our ack).
static bool s_fw_mac_known
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 const char * internal_net_echo_state(void)
One-word verdict for the TCP echo leg of the run report.
static bool s_tcp_match
Echo matched what we sent.
net_console_t
Console-tap line buffer capacity for a network packet summary.
@ k_net_console_line_cap
Max chars in a "NET tx eth=.." line.
void board_net_tick(void)
Advance the peer's state machine one tick (ARP -> ping -> TCP echo).
static RA8_INTERNAL void internal_put32(uint8_t *p, uint32_t v)
Store a 32-bit value big-endian at p.
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.
Virtual network peer for ra8_emulator – talks TCP/IP to the firmware.
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
static volatile uint32_t s_trace[k_dcd_trace_entries]
JLink-readable ring of packed transfer/SETUP events.