Add medium-ip, medium-ethernet Cargo features
This commit is contained in:
parent
28c235d786
commit
4f528d8fae
9
ci.sh
9
ci.sh
@ -3,11 +3,14 @@
|
|||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
# build for std
|
# build for std
|
||||||
(cd embassy-net; cargo build --features log)
|
(cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,tcp)
|
||||||
|
(cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,tcp,dhcpv4)
|
||||||
|
(cd embassy-net; cargo build --no-default-features --features log,medium-ip,tcp)
|
||||||
|
(cd embassy-net; cargo build --no-default-features --features log,medium-ethernet,medium-ip,tcp,dhcpv4)
|
||||||
|
|
||||||
# build for embedded
|
# build for embedded
|
||||||
(cd embassy-net; cargo build --target thumbv7em-none-eabi --features log)
|
(cd embassy-net; cargo build --target thumbv7em-none-eabi --no-default-features --features log,medium-ethernet,medium-ip,tcp,dhcpv4)
|
||||||
(cd embassy-net; cargo build --target thumbv7em-none-eabi --features defmt,smoltcp/defmt)
|
(cd embassy-net; cargo build --target thumbv7em-none-eabi --no-default-features --features defmt,smoltcp/defmt,medium-ethernet,medium-ip,tcp,dhcpv4)
|
||||||
|
|
||||||
# build examples
|
# build examples
|
||||||
(cd embassy-net-examples; cargo build)
|
(cd embassy-net-examples; cargo build)
|
||||||
|
@ -8,7 +8,7 @@ edition = "2018"
|
|||||||
heapless = { version = "0.5.6", default-features = false }
|
heapless = { version = "0.5.6", default-features = false }
|
||||||
embassy = { version = "0.1.0", features=["std", "log"] }
|
embassy = { version = "0.1.0", features=["std", "log"] }
|
||||||
embassy-std = { version = "0.1.0" }
|
embassy-std = { version = "0.1.0" }
|
||||||
embassy-net = { version = "0.1.0", path = "../embassy-net", features=["std", "log", "tcp", "dhcpv4"] }
|
embassy-net = { version = "0.1.0", path = "../embassy-net", features=["std", "log", "medium-ethernet", "tcp", "dhcpv4"] }
|
||||||
env_logger = "0.8.2"
|
env_logger = "0.8.2"
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
futures = "0.3.8"
|
futures = "0.3.8"
|
||||||
@ -16,3 +16,4 @@ libc = "0.2.81"
|
|||||||
async-io = "1.3.1"
|
async-io = "1.3.1"
|
||||||
smoltcp = { version = "0.7.0", default-features = false }
|
smoltcp = { version = "0.7.0", default-features = false }
|
||||||
clap = { version = "3.0.0-beta.2", features = ["derive"] }
|
clap = { version = "3.0.0-beta.2", features = ["derive"] }
|
||||||
|
rand_core = { version = "0.6.0", features = ["std"] }
|
||||||
|
@ -13,7 +13,9 @@ defmt-warn = []
|
|||||||
defmt-error = []
|
defmt-error = []
|
||||||
|
|
||||||
tcp = ["smoltcp/socket-tcp"]
|
tcp = ["smoltcp/socket-tcp"]
|
||||||
dhcpv4 = ["smoltcp/socket-dhcpv4"]
|
dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"]
|
||||||
|
medium-ethernet = ["smoltcp/medium-ethernet"]
|
||||||
|
medium-ip = ["smoltcp/medium-ip"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
@ -36,15 +38,7 @@ version = "0.7.0"
|
|||||||
#rev = "00952e2c5cdf5667a1dfb6142258055f58d3851c"
|
#rev = "00952e2c5cdf5667a1dfb6142258055f58d3851c"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"medium-ethernet",
|
|
||||||
"medium-ip",
|
|
||||||
"proto-ipv4",
|
"proto-ipv4",
|
||||||
#"proto-dhcpv4",
|
"socket",
|
||||||
#"proto-igmp",
|
|
||||||
#"proto-ipv6",
|
|
||||||
#"socket-raw",
|
|
||||||
#"socket-icmp",
|
|
||||||
#"socket-udp",
|
|
||||||
#"socket-tcp",
|
|
||||||
"async",
|
"async",
|
||||||
]
|
]
|
||||||
|
@ -12,9 +12,10 @@ mod device;
|
|||||||
mod packet_pool;
|
mod packet_pool;
|
||||||
mod stack;
|
mod stack;
|
||||||
|
|
||||||
pub use config::{
|
#[cfg(feature = "dhcpv4")]
|
||||||
Config, Configurator, DhcpConfigurator, Event as ConfigEvent, StaticConfigurator,
|
pub use config::DhcpConfigurator;
|
||||||
};
|
pub use config::{Config, Configurator, Event as ConfigEvent, StaticConfigurator};
|
||||||
|
|
||||||
pub use device::{Device, LinkState};
|
pub use device::{Device, LinkState};
|
||||||
pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf};
|
pub use packet_pool::{Packet, PacketBox, PacketBoxExt, PacketBuf};
|
||||||
pub use stack::{init, is_init, run};
|
pub use stack::{init, is_init, run};
|
||||||
|
@ -6,12 +6,16 @@ use embassy::time::{Instant, Timer};
|
|||||||
use embassy::util::ThreadModeMutex;
|
use embassy::util::ThreadModeMutex;
|
||||||
use embassy::util::{Forever, WakerRegistration};
|
use embassy::util::{Forever, WakerRegistration};
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use smoltcp::iface::{InterfaceBuilder, Neighbor, NeighborCache, Route, Routes};
|
use smoltcp::iface::InterfaceBuilder;
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes};
|
||||||
use smoltcp::phy::Device as _;
|
use smoltcp::phy::Device as _;
|
||||||
use smoltcp::phy::Medium;
|
use smoltcp::phy::Medium;
|
||||||
use smoltcp::socket::SocketSetItem;
|
use smoltcp::socket::SocketSetItem;
|
||||||
use smoltcp::time::Instant as SmolInstant;
|
use smoltcp::time::Instant as SmolInstant;
|
||||||
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
use smoltcp::wire::EthernetAddress;
|
||||||
|
use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
|
||||||
|
|
||||||
use crate::config::Configurator;
|
use crate::config::Configurator;
|
||||||
use crate::config::Event;
|
use crate::config::Event;
|
||||||
@ -27,9 +31,12 @@ const LOCAL_PORT_MAX: u16 = 65535;
|
|||||||
|
|
||||||
struct StackResources {
|
struct StackResources {
|
||||||
addresses: [IpCidr; ADDRESSES_LEN],
|
addresses: [IpCidr; ADDRESSES_LEN],
|
||||||
neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR_CACHE_LEN],
|
|
||||||
sockets: [Option<SocketSetItem<'static>>; SOCKETS_LEN],
|
sockets: [Option<SocketSetItem<'static>>; SOCKETS_LEN],
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
routes: [Option<(IpCidr, Route)>; 1],
|
routes: [Option<(IpCidr, Route)>; 1],
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR_CACHE_LEN],
|
||||||
}
|
}
|
||||||
|
|
||||||
static STACK_RESOURCES: Forever<StackResources> = Forever::new();
|
static STACK_RESOURCES: Forever<StackResources> = Forever::new();
|
||||||
@ -79,6 +86,7 @@ impl Stack {
|
|||||||
debug!(" IP address: {}", config.address);
|
debug!(" IP address: {}", config.address);
|
||||||
set_ipv4_addr(&mut self.iface, config.address);
|
set_ipv4_addr(&mut self.iface, config.address);
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
if let Some(gateway) = config.gateway {
|
if let Some(gateway) = config.gateway {
|
||||||
debug!(" Default gateway: {}", gateway);
|
debug!(" Default gateway: {}", gateway);
|
||||||
@ -98,6 +106,7 @@ impl Stack {
|
|||||||
Event::Deconfigured => {
|
Event::Deconfigured => {
|
||||||
debug!("Lost IP configuration");
|
debug!("Lost IP configuration");
|
||||||
set_ipv4_addr(&mut self.iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
|
set_ipv4_addr(&mut self.iface, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
self.iface.routes_mut().remove_default_ipv4_route();
|
self.iface.routes_mut().remove_default_ipv4_route();
|
||||||
}
|
}
|
||||||
@ -156,12 +165,17 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf
|
|||||||
const NONE_SOCKET: Option<SocketSetItem<'static>> = None;
|
const NONE_SOCKET: Option<SocketSetItem<'static>> = None;
|
||||||
let res = STACK_RESOURCES.put(StackResources {
|
let res = STACK_RESOURCES.put(StackResources {
|
||||||
addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32)],
|
addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32)],
|
||||||
neighbor_cache: [None; NEIGHBOR_CACHE_LEN],
|
|
||||||
sockets: [NONE_SOCKET; SOCKETS_LEN],
|
sockets: [NONE_SOCKET; SOCKETS_LEN],
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
routes: [None; 1],
|
routes: [None; 1],
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
neighbor_cache: [None; NEIGHBOR_CACHE_LEN],
|
||||||
});
|
});
|
||||||
|
|
||||||
let medium = device.capabilities().medium;
|
let medium = device.capabilities().medium;
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let ethernet_addr = if medium == Medium::Ethernet {
|
let ethernet_addr = if medium == Medium::Ethernet {
|
||||||
device.ethernet_address()
|
device.ethernet_address()
|
||||||
} else {
|
} else {
|
||||||
@ -171,6 +185,7 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf
|
|||||||
let mut b = InterfaceBuilder::new(DeviceAdapter::new(device));
|
let mut b = InterfaceBuilder::new(DeviceAdapter::new(device));
|
||||||
b = b.ip_addrs(&mut res.addresses[..]);
|
b = b.ip_addrs(&mut res.addresses[..]);
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
b = b.ethernet_addr(EthernetAddress(ethernet_addr));
|
b = b.ethernet_addr(EthernetAddress(ethernet_addr));
|
||||||
b = b.neighbor_cache(NeighborCache::new(&mut res.neighbor_cache[..]));
|
b = b.neighbor_cache(NeighborCache::new(&mut res.neighbor_cache[..]));
|
||||||
|
Loading…
Reference in New Issue
Block a user