File syn_eth.c¶
Go to the source code of this file
Zero-Heap Native Ethernet II & ARP Protocol Engine Implementation.
#include "syntropic/net/syn_eth.h"#include "syntropic/net/syn_icmp.h"#include "syntropic/net/syn_tcp.h"#include "syntropic/net/syn_transport_udp.h"#include "syntropic/net/syn_udp.h"#include "syntropic/port/syn_port_system.h"#include "syntropic/util/syn_crc.h"#include <string.h>
Public Static Attributes¶
| Type | Name |
|---|---|
| const uint8_t | MAC_BROADCAST = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_eth_arp_lookup (SYN_ETH * eth, uint32_t ip, uint8_t mac_out) Lookup MAC address in local ARP cache table. |
| SYN_Status | syn_eth_arp_update (SYN_ETH * eth, uint32_t ip, const uint8_t mac) Update or insert an entry into the local ARP cache table. |
| SYN_Status | syn_eth_build_frame (SYN_ETH * eth, const uint8_t dst_mac, uint16_t ethertype, const uint8_t * payload, size_t payload_len, uint8_t * frame_out, size_t * frame_len) Build and transmit an outbound Ethernet II frame. |
| SYN_Status | syn_eth_generate_mac (const void * uid_bytes, size_t uid_len, uint8_t mac_out) Generate a deterministic Locally Administered MAC address from MCU Unique ID. |
| SYN_WEAK struct SYN_ICMP * | syn_eth_get_icmp_instance (void) Weak hook — override to inject an ICMP engine into the Ethernet dispatcher. |
| SYN_WEAK struct SYN_TCP * | syn_eth_get_tcp_instance (void) Weak hook — override to inject a TCP engine into the Ethernet dispatcher. |
| SYN_Status | syn_eth_init (SYN_ETH * eth, const uint8_t mac_addr, uint32_t ip_addr) Initialize Native Ethernet Engine. |
| size_t | syn_eth_pack_header (uint8_t * buf, size_t buf_size, const uint8_t dst_mac, const uint8_t src_mac, uint16_t ethertype) Pack Ethernet II Header (14 bytes) into target buffer. |
| SYN_Status | syn_eth_process_frame (SYN_ETH * eth, const uint8_t * frame, size_t len, uint8_t * tx_buf, size_t * tx_len) Process incoming Ethernet II frame. |
| uint16_t | syn_ip_checksum (const void * buf, size_t len) Calculate 16-bit Internet Checksum (RFC 1071) over buffer. |
| size_t | syn_ip_pack_header (uint8_t * buf, size_t buf_size, uint32_t src_ip, uint32_t dst_ip, uint8_t proto, uint16_t payload_len, uint16_t id) Pack standard 20-byte IPv4 Header into target buffer. |
| SYN_WEAK SYN_UDP * | syn_transport_udp_get_instance (void) Weak hook to obtain UDP transport instance. |
Public Static Attributes Documentation¶
variable MAC_BROADCAST¶
Broadcast MAC address (FF:FF:FF:FF:FF:FF)
Public Functions Documentation¶
function syn_eth_arp_lookup¶
Lookup MAC address in local ARP cache table.
Parameters:
ethPointer to Ethernet instance.ip32-bit IPv4 address to lookup.mac_outOutput buffer (6 bytes) to receive resolved MAC.
Returns:
SYN_OK if IP found in cache, SYN_NOT_FOUND if absent.
function syn_eth_arp_update¶
Update or insert an entry into the local ARP cache table.
Parameters:
ethPointer to Ethernet instance.ip32-bit IPv4 address.macResolved 6-byte MAC address.
Returns:
SYN_OK on success.
function syn_eth_build_frame¶
Build and transmit an outbound Ethernet II frame.
SYN_Status syn_eth_build_frame (
SYN_ETH * eth,
const uint8_t dst_mac,
uint16_t ethertype,
const uint8_t * payload,
size_t payload_len,
uint8_t * frame_out,
size_t * frame_len
)
Parameters:
ethPointer to Ethernet instance.dst_macDestination MAC address (6 bytes).ethertypeEtherType value (e.g. SYN_ETHTYPE_IPV4).payloadPointer to payload buffer.payload_lenPayload byte length.frame_outOutput frame buffer (must hold at least 1514 bytes).frame_lenPointer to receive final raw Ethernet frame length.
Returns:
SYN_OK on success.
function syn_eth_generate_mac¶
Generate a deterministic Locally Administered MAC address from MCU Unique ID.
Parameters:
uid_bytesPointer to hardware unique ID bytes (e.g. STM32 96-bit UID).uid_lenLength of unique ID in bytes.mac_outOutput buffer to receive generated 6-byte MAC address.
Returns:
SYN_OK on success.
function syn_eth_get_icmp_instance¶
Weak hook — override to inject an ICMP engine into the Ethernet dispatcher.
When syn_eth_process_frame receives an IPv4/ICMP packet (protocol 1), it calls this to obtain the ICMP instance. Return NULL to silently drop.
Returns:
Pointer to SYN_ICMP instance, or NULL.
function syn_eth_get_tcp_instance¶
Weak hook — override to inject a TCP engine into the Ethernet dispatcher.
When syn_eth_process_frame receives an IPv4/TCP packet (protocol 6), it calls this to obtain the TCP instance. Return NULL to silently drop.
Returns:
Pointer to SYN_TCP instance, or NULL.
function syn_eth_init¶
Initialize Native Ethernet Engine.
Parameters:
ethPointer to Ethernet instance.mac_addr6-byte hardware MAC address.ip_addr32-bit IPv4 address (host byte order).
Returns:
SYN_OK on success.
function syn_eth_pack_header¶
Pack Ethernet II Header (14 bytes) into target buffer.
size_t syn_eth_pack_header (
uint8_t * buf,
size_t buf_size,
const uint8_t dst_mac,
const uint8_t src_mac,
uint16_t ethertype
)
Parameters:
bufOutput destination buffer.buf_sizeDestination buffer capacity.dst_macDestination 6-byte MAC address.src_macSource 6-byte MAC address.ethertype16-bit EtherType (host byte order).
Returns:
Bytes written (14) on success, 0 on invalid param / insufficient buffer.
function syn_eth_process_frame¶
Process incoming Ethernet II frame.
SYN_Status syn_eth_process_frame (
SYN_ETH * eth,
const uint8_t * frame,
size_t len,
uint8_t * tx_buf,
size_t * tx_len
)
Parameters:
ethPointer to Ethernet instance.framePointer to raw frame bytes.lenFrame byte length (60..1514 bytes).tx_bufOutput buffer to receive immediate ARP reply if generated.tx_lenPointer to receive ARP reply byte length (0 if no reply needed).
Returns:
SYN_OK on success.
function syn_ip_checksum¶
Calculate 16-bit Internet Checksum (RFC 1071) over buffer.
Parameters:
bufPointer to buffer.lenBuffer byte length.
Returns:
16-bit one's complement checksum.
function syn_ip_pack_header¶
Pack standard 20-byte IPv4 Header into target buffer.
size_t syn_ip_pack_header (
uint8_t * buf,
size_t buf_size,
uint32_t src_ip,
uint32_t dst_ip,
uint8_t proto,
uint16_t payload_len,
uint16_t id
)
Parameters:
bufOutput destination buffer.buf_sizeDestination buffer capacity.src_ipSource IPv4 address (host byte order).dst_ipDestination IPv4 address (host byte order).protoIP Protocol number (1=ICMP, 2=IGMP, 6=TCP, 17=UDP).payload_lenPayload byte length after IPv4 header.id16-bit IP identification field.
Returns:
Bytes written (20) on success, 0 on invalid param / insufficient buffer.
function syn_transport_udp_get_instance¶
Weak hook to obtain UDP transport instance.
Get the active native SYN_UDP stack instance.
Returns:
Pointer to global SYN_UDP instance, or NULL if unavailable.
The documentation for this class was generated from the following file src/syntropic/net/syn_eth.c