diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-04-12 21:00:23 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-04-12 21:00:23 +0200 |
| commit | 4f528d8fae0c57fad5c5a57f5a61fd0fc4435044 (patch) | |
| tree | b3f135aa2f35a2038726fa013c56351fba2b7a20 | |
| parent | 28c235d7866f2a0defaf235270ade6dbee10fc9e (diff) | |
Add medium-ip, medium-ethernet Cargo features
| -rwxr-xr-x | ci.sh | 9 | ||||
| -rw-r--r-- | embassy-net-examples/Cargo.toml | 5 | ||||
| -rw-r--r-- | embassy-net/Cargo.toml | 14 | ||||
| -rw-r--r-- | embassy-net/src/lib.rs | 7 | ||||
| -rw-r--r-- | embassy-net/src/stack.rs | 23 |
5 files changed, 36 insertions, 22 deletions
| @@ -3,11 +3,14 @@ | |||
| 3 | set -euxo pipefail | 3 | set -euxo pipefail |
| 4 | 4 | ||
| 5 | # build for std | 5 | # build for std |
| 6 | (cd embassy-net; cargo build --features log) | 6 | (cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,tcp) |
| 7 | (cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,tcp,dhcpv4) | ||
| 8 | (cd embassy-net; cargo build --no-default-features --features log,medium-ip,tcp) | ||
| 9 | (cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,medium-ip,tcp,dhcpv4) | ||
| 7 | 10 | ||
| 8 | # build for embedded | 11 | # build for embedded |
| 9 | (cd embassy-net; cargo build --target thumbv7em-none-eabi --features log) | 12 | (cd embassy-net; cargo build --target thumbv7em-none-eabi --no-default-features --features log,medium-ethernet,medium-ip,tcp,dhcpv4) |
| 10 | (cd embassy-net; cargo build --target thumbv7em-none-eabi --features defmt,smoltcp/defmt) | 13 | (cd embassy-net; cargo build --target thumbv7em-none-eabi --no-default-features --features defmt,smoltcp/defmt,medium-ethernet,medium-ip,tcp,dhcpv4) |
| 11 | 14 | ||
| 12 | # build examples | 15 | # build examples |
| 13 | (cd embassy-net-examples; cargo build) | 16 | (cd embassy-net-examples; cargo build) |
diff --git a/embassy-net-examples/Cargo.toml b/embassy-net-examples/Cargo.toml index 796c44745..0a63a3bbd 100644 --- a/embassy-net-examples/Cargo.toml +++ b/embassy-net-examples/Cargo.toml | |||
| @@ -8,11 +8,12 @@ edition = "2018" | |||
| 8 | heapless = { version = "0.5.6", default-features = false } | 8 | heapless = { version = "0.5.6", default-features = false } |
| 9 | embassy = { version = "0.1.0", features=["std", "log"] } | 9 | embassy = { version = "0.1.0", features=["std", "log"] } |
| 10 | embassy-std = { version = "0.1.0" } | 10 | embassy-std = { version = "0.1.0" } |
| 11 | embassy-net = { version = "0.1.0", path = "../embassy-net", features=["std", "log", "tcp", "dhcpv4"] } | 11 | embassy-net = { version = "0.1.0", path = "../embassy-net", features=["std", "log", "medium-ethernet", "tcp", "dhcpv4"] } |
| 12 | env_logger = "0.8.2" | 12 | env_logger = "0.8.2" |
| 13 | log = "0.4.11" | 13 | log = "0.4.11" |
| 14 | futures = "0.3.8" | 14 | futures = "0.3.8" |
| 15 | libc = "0.2.81" | 15 | libc = "0.2.81" |
| 16 | async-io = "1.3.1" | 16 | async-io = "1.3.1" |
| 17 | smoltcp = { version = "0.7.0", default-features = false } | 17 | smoltcp = { version = "0.7.0", default-features = false } |
| 18 | clap = { version = "3.0.0-beta.2", features = ["derive"] } \ No newline at end of file | 18 | clap = { version = "3.0.0-beta.2", features = ["derive"] } |
| 19 | rand_core = { version = "0.6.0", features = ["std"] } | ||
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index dccd7984d..b419250be 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml | |||
| @@ -13,7 +13,9 @@ defmt-warn = [] | |||
| 13 | defmt-error = [] | 13 | defmt-error = [] |
| 14 | 14 | ||
| 15 | tcp = ["smoltcp/socket-tcp"] | 15 | tcp = ["smoltcp/socket-tcp"] |
| 16 | dhcpv4 = ["smoltcp/socket-dhcpv4"] | 16 | dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] |
| 17 | medium-ethernet = ["smoltcp/medium-ethernet"] | ||
| 18 | medium-ip = ["smoltcp/medium-ip"] | ||
| 17 | 19 | ||
| 18 | [dependencies] | 20 | [dependencies] |
| 19 | 21 | ||
| @@ -36,15 +38,7 @@ version = "0.7.0" | |||
| 36 | #rev = "00952e2c5cdf5667a1dfb6142258055f58d3851c" | 38 | #rev = "00952e2c5cdf5667a1dfb6142258055f58d3851c" |
| 37 | default-features = false | 39 | default-features = false |
| 38 | features = [ | 40 | features = [ |
| 39 | "medium-ethernet", | ||
| 40 | "medium-ip", | ||
| 41 | "proto-ipv4", | 41 | "proto-ipv4", |
| 42 | #"proto-dhcpv4", | 42 | "socket", |
| 43 | #"proto-igmp", | ||
| 44 | #"proto-ipv6", | ||
| 45 | #"socket-raw", | ||
| 46 | #"socket-icmp", | ||
| 47 | #"socket-udp", | ||
| 48 | #"socket-tcp", | ||
| 49 | "async", | 43 | "async", |
| 50 | ] | 44 | ] |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index edfb2c26d..efa5f3cb1 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -12,9 +12,10 @@ mod device; | |||
| 12 | mod packet_pool; | 12 | mod packet_pool; |
| 13 | mod stack; | 13 | mod stack; |
| 14 | 14 | ||
| 15 | pub use config::{ | 15 | #[cfg(feature = "dhcpv4")] |
| 16 | Config, Configurator, DhcpConfigurator, Event as ConfigEvent, StaticConfigurator, | 16 | pub use config::DhcpConfigurator; |
| 17 | }; | 17 | pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator}; |
| 18 | |||
| 18 | pub use device::{Device, LinkState}; | 19 | pub use device::{Device, LinkState}; |
| 19 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; | 20 | pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf}; |
| 20 | pub use stack::{init, is_init, run}; | 21 | pub use stack::{init, is_init, run}; |
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 9b0dd54d4..83cd71707 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -6,12 +6,16 @@ use embassy::time::{Instant, Timer}; | |||
| 6 | use embassy::util::ThreadModeMutex; | 6 | use embassy::util::ThreadModeMutex; |
| 7 | use embassy::util::{Forever, WakerRegistration}; | 7 | use embassy::util::{Forever, WakerRegistration}; |
| 8 | use futures::pin_mut; | 8 | use futures::pin_mut; |
| 9 | use smoltcp::iface::{InterfaceBuilder, Neighbor, NeighborCache, Route, Routes}; | 9 | use smoltcp::iface::InterfaceBuilder; |
| 10 | #[cfg(feature = "medium-ethernet")] | ||
| 11 | use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; | ||
| 10 | use smoltcp::phy::Device as _; | 12 | use smoltcp::phy::Device as _; |
| 11 | use smoltcp::phy::Medium; | 13 | use smoltcp::phy::Medium; |
| 12 | use smoltcp::socket::SocketSetItem; | 14 | use smoltcp::socket::SocketSetItem; |
| 13 | use smoltcp::time::Instant as SmolInstant; | 15 | use smoltcp::time::Instant as SmolInstant; |
| 14 | use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | 16 | #[cfg(feature = "medium-ethernet")] |
| 17 | use smoltcp::wire::EthernetAddress; | ||
| 18 | use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | ||
| 15 | 19 | ||
| 16 | use crate::config::Configurator; | 20 | use crate::config::Configurator; |
| 17 | use crate::config::Event; | 21 | use crate::config::Event; |
| @@ -27,9 +31,12 @@ const LOCAL_PORT_MAX: u16 = 65535; | |||
| 27 | 31 | ||
| 28 | struct StackResources { | 32 | struct StackResources { |
| 29 | addresses: [IpCidr; ADDRESSES_LEN], | 33 | addresses: [IpCidr; ADDRESSES_LEN], |
| 30 | neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR_CACHE_LEN], | ||
| 31 | sockets: [Option<SocketSetItem<'static>>; SOCKETS_LEN], | 34 | sockets: [Option<SocketSetItem<'static>>; SOCKETS_LEN], |
| 35 | |||
| 36 | #[cfg(feature = "medium-ethernet")] | ||
| 32 | routes: [Option<(IpCidr, Route)>; 1], | 37 | routes: [Option<(IpCidr, Route)>; 1], |
| 38 | #[cfg(feature = "medium-ethernet")] | ||
| 39 | neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR_CACHE_LEN], | ||
| 33 | } | 40 | } |
| 34 | 41 | ||
| 35 | static STACK_RESOURCES: Forever<StackResources> = Forever::new(); | 42 | static STACK_RESOURCES: Forever<StackResources> = Forever::new(); |
| @@ -79,6 +86,7 @@ impl Stack { | |||
| 79 | debug!(" IP address: {}", config.address); | 86 | debug!(" IP address: {}", config.address); |
| 80 | set_ipv4_addr(&mut self.iface, config.address); | 87 | set_ipv4_addr(&mut self.iface, config.address); |
| 81 | 88 | ||
| 89 | #[cfg(feature = "medium-ethernet")] | ||
| 82 | if medium == Medium::Ethernet { | 90 | if medium == Medium::Ethernet { |
| 83 | if let Some(gateway) = config.gateway { | 91 | if let Some(gateway) = config.gateway { |
| 84 | debug!(" Default gateway: {}", gateway); | 92 | debug!(" Default gateway: {}", gateway); |
| @@ -98,6 +106,7 @@ impl Stack { | |||
| 98 | Event::Deconfigured => { | 106 | Event::Deconfigured => { |
| 99 | debug!("Lost IP configuration"); | 107 | debug!("Lost IP configuration"); |
| 100 | set_ipv4_addr(&mut self.iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0)); | 108 | set_ipv4_addr(&mut self.iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0)); |
| 109 | #[cfg(feature = "medium-ethernet")] | ||
| 101 | if medium == Medium::Ethernet { | 110 | if medium == Medium::Ethernet { |
| 102 | self.iface.routes_mut().remove_default_ipv4_route(); | 111 | self.iface.routes_mut().remove_default_ipv4_route(); |
| 103 | } | 112 | } |
| @@ -156,12 +165,17 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf | |||
| 156 | const NONE_SOCKET: Option<SocketSetItem<'static>> = None; | 165 | const NONE_SOCKET: Option<SocketSetItem<'static>> = None; |
| 157 | let res = STACK_RESOURCES.put(StackResources { | 166 | let res = STACK_RESOURCES.put(StackResources { |
| 158 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32)], | 167 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32)], |
| 159 | neighbor_cache: [None; NEIGHBOR_CACHE_LEN], | ||
| 160 | sockets: [NONE_SOCKET; SOCKETS_LEN], | 168 | sockets: [NONE_SOCKET; SOCKETS_LEN], |
| 169 | |||
| 170 | #[cfg(feature = "medium-ethernet")] | ||
| 161 | routes: [None; 1], | 171 | routes: [None; 1], |
| 172 | #[cfg(feature = "medium-ethernet")] | ||
| 173 | neighbor_cache: [None; NEIGHBOR_CACHE_LEN], | ||
| 162 | }); | 174 | }); |
| 163 | 175 | ||
| 164 | let medium = device.capabilities().medium; | 176 | let medium = device.capabilities().medium; |
| 177 | |||
| 178 | #[cfg(feature = "medium-ethernet")] | ||
| 165 | let ethernet_addr = if medium == Medium::Ethernet { | 179 | let ethernet_addr = if medium == Medium::Ethernet { |
| 166 | device.ethernet_address() | 180 | device.ethernet_address() |
| 167 | } else { | 181 | } else { |
| @@ -171,6 +185,7 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf | |||
| 171 | let mut b = InterfaceBuilder::new(DeviceAdapter::new(device)); | 185 | let mut b = InterfaceBuilder::new(DeviceAdapter::new(device)); |
| 172 | b = b.ip_addrs(&mut res.addresses[..]); | 186 | b = b.ip_addrs(&mut res.addresses[..]); |
| 173 | 187 | ||
| 188 | #[cfg(feature = "medium-ethernet")] | ||
| 174 | if medium == Medium::Ethernet { | 189 | if medium == Medium::Ethernet { |
| 175 | b = b.ethernet_addr(EthernetAddress(ethernet_addr)); | 190 | b = b.ethernet_addr(EthernetAddress(ethernet_addr)); |
| 176 | b = b.neighbor_cache(NeighborCache::new(&mut res.neighbor_cache[..])); | 191 | b = b.neighbor_cache(NeighborCache::new(&mut res.neighbor_cache[..])); |
