Expand description
§embassy-net
embassy-net is a no-std no-alloc async network stack, designed for embedded systems.
It uses the xarxa network stack, and adds convenient
async wrappers on top of it and implements the main loop for you.
§Features
- IPv4, IPv6
- Ethernet, IP and IEEE 802.15.4 / 6LoWPAN mediums.
- TCP, UDP, raw sockets, DNS, DHCPv4
- TCP sockets implement the
embedded-ioasync traits. - Multicast
- Multiple interface support
- Timestamping sent and received packets for e.g PTP
See the xarxa README for a detailed list of implemented and
unimplemented features of the network protocols.
Embassy-net focuses on the network/transport layer protocols up to TCP. Higher-level application layer protocols live in other crates built on top of embassy-net:
§Hardware support
esp-radiofor WiFi support ESP32 chips. Maintained by Espressif.cyw43for WiFi on CYW43xx chips, used in the Raspberry Pi Pico Wembassy-usbfor Ethernet-over-USB (CDC NCM) support.embassy-stm32for the builtin Ethernet MAC in all STM32 chips (STM32F1, STM32F2, STM32F4, STM32F7, STM32H7, STM32H5).embassy-net-wiznetfor Wiznet SPI Ethernet MAC+PHY chips (W5100S, W5500)embassy-net-enc28j60for the Microchip ENC28J60 SPI Ethernet MAC+PHY chip.embassy-net-adin1110for the Analog Devices ADIN1110 SPI 10BASE-T1L single-pair Ethernet chip.embassy-net-esp-hostedfor using ESP32 chips with theesp-hostedfirmware as WiFi adapters for another non-ESP32 MCU.embassy-net-nrf91for the cellular modem in Nordic nRF91-series chips.embassy-net-pppfor PPP over Serial, useful with cellular modems or for a network link to a host computer.embassy-nrffor IEEE 802.15.4 support on nrf chips.embassy-stm32-wpanfor IEEE 802.15.4 support on STM32WB chips.embassy-net-tuntapfor Linux TUN/TAP interfaces, useful for running onstdplatforms.
§Examples
- For usage with Embassy HALs and network chip drivers, search here for
ethorwifi. - The
esp-halrepo has examples for use on bare-metal ESP32 chips. - For usage on
stdplatforms, see thestdexamples
§Adding support for new hardware
To add embassy-net support for new hardware (i.e. a new Ethernet or WiFi chip, or
an Ethernet/WiFi MCU peripheral), you have to implement the xarxa-driver
Driver trait. Enable its async feature and implement Driver::register_waker: embassy-net
needs it to sleep until the driver has something new.
Drivers should depend only on xarxa-driver. Never on the main embassy-net crate. This allows
existing drivers to continue working for newer embassy-net major versions, without needing an
update, if the driver trait has not had breaking changes.
§Interoperability
This crate can run on any executor.
embassy-time is used for timekeeping and timeouts. You must
link an embassy-time driver in your project to use this crate.
§Feature flags
alloc— Enable APIs that use the heap.
§Protocol support
medium-ethernet— Support interfaces that send and receive Ethernet frames, with the link-layer machinery that goes with them (ARP, NDISC, the neighbor cache).medium-ip— Support interfaces that send and receive bare IP packets, without a link-layer header.medium-ieee802154— Support IEEE 802.15.4 interfaces carrying 6LoWPAN (RFC 4944, RFC 6282). Needsipv6.sixlowpan-fragmentation— Fragment outgoing 6LoWPAN packets larger than one 802.15.4 frame. Needsmedium-ieee802154.sixlowpan-reassembly— Reassemble incoming 6LoWPAN fragments. Needsmedium-ieee802154.ipv4— Support IPv4 (and, withmedium-ethernet, ARP).ipv4-fragmentation— Fragment outgoing IPv4 packets larger than the interface MTU. Needsipv4.ipv4-reassembly— Reassemble incoming IPv4 fragments. Needsipv4.ipv6— Support IPv6 (and, withmedium-ethernet, NDISC).raw-ethernet— Ethernet-mode raw sockets: send and receive whole Ethernet frames. Needsmedium-ethernet.raw-ip— IP-mode raw sockets: send and receive whole IP packets.udp— UDP sockets.tcp— TCP sockets.tcp-listener— TCP listeners, for accepting incoming connections.dhcpv4— DHCPv4 client, built into the interface. Needsipv4andmedium-ethernet.dhcpv4-options— Allow reading received DHCP options.dhcpv4-server— DHCPv4 server, built into the interface. Needsipv4andmedium-ethernet.hostname— Give the stack a hostname, withStack::set_hostname. If set, it is sent to the DHCP server in outgoing DHCP messages.slaac— IPv6 stateless address autoconfiguration (SLAAC). Needsipv6, andmedium-ethernetormedium-ieee802154.dns— DNS client.embedded-nal— Implement theembedded-nal-asynctraits, withtcp::client::TcpClientanddns::DnsClient.mdns— Resolve.localnames with multicast DNS in the DNS client.multicast— Join IP multicast groups, with IGMP (IPv4) and MLD (IPv6) membership reports.tcp-timestamps— Send and receive the TCP timestamp option (RFC 7323).tcp-sack— Send selective acknowledgement ranges (RFC 2018).icmp-ping-reply— Automatically reply to pings (ICMP echo requests).iface-bind— Bind sockets to an interface withbind_to_iface. A bound socket only receives packets that arrive on that interface, and only sends out of it.icmp-errors— Deliver incoming ICMP error messages (destination unreachable, packet too big, …) to the sockets that provoked them.
§TCP congestion control
Enable one of these features to enable congestion control. No feature enabled means no congestion control. You may enable at most one.
tcp-reno— Use the Reno congestion control algorithm on TCP sockets.tcp-cubic— Use the CUBIC congestion control algorithm on TCP sockets. Warning: it usesf64arithmetic which can be slow and pull in soft-float code depending on the target.
§Packet metadata
packetmeta-id— Enable thePacketMeta::idfield: an opaque number that travels with a packet through the whole stack.packetmeta-timestamp— Enable thePacketMeta::timestampandPacketMeta::request_timestampfields, andDriver::poll_tx_timestamp.
§Logging
log— Log with thelogcrate.defmt— Log with thedefmtcrate.packet-log— Log every packet received and sent, decoded. Needslogordefmtto print anything.
Re-exports§
pub use xarxa_driver as driver;
Modules§
- config
- Compile-time configuration.
- dns
- DNS client compatible with the
embedded-nal-asynctraits. - iface
- Network interfaces.
- raw
- Raw sockets.
- route
- IP routing table.
- tcp
- TCP sockets.
- udp
- UDP sockets.
- wire
- Low-level packet access and construction.
Structs§
- Full
- A table, slab or queue has no room for another item.
- Neighbor
- A neighbor: the mapping of an on-link IP address to a hardware address.
- Neighbor
Cache - The stack’s neighbor cache, returned by
Stack::neighbor_cache. - Runner
- Network stack runner.
- Stack
- A network stack.
- Stack
Storage - Memory storage needed for a network stack.
Enums§
- Neighbor
State - State of a
Neighborentry. - TryError
- Error returned by
try_*socket methods.