Merge pull request #1535 from rubdos/v4-optional
Add IPv6 to Embassy net, make IPv4 optional
This commit is contained in:
commit
2e0bc71c86
10
ci.sh
10
ci.sh
@ -25,11 +25,19 @@ cargo batch \
|
|||||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
||||||
--- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
--- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
||||||
--- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,defmt,defmt-timestamp-uptime,tick-hz-32_768,generic-queue-8 \
|
--- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,defmt,defmt-timestamp-uptime,tick-hz-32_768,generic-queue-8 \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,medium-ethernet \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,nightly \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,nightly \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits,nightly \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits,nightly \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,nightly \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits,nightly \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet,unstable-traits \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet,nightly \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet,unstable-traits,nightly \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52805,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52805,gpiote,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52810,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52810,gpiote,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52811,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52811,gpiote,time-driver-rtc1 \
|
||||||
|
@ -14,9 +14,11 @@ cargo batch \
|
|||||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \
|
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \
|
||||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \
|
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \
|
||||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \
|
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,medium-ethernet \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
|
||||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \
|
||||||
|
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time-driver-rtc1 \
|
||||||
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time-driver-rtc1 \
|
--- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time-driver-rtc1 \
|
||||||
|
@ -26,7 +26,8 @@ unstable-traits = []
|
|||||||
udp = ["smoltcp/socket-udp"]
|
udp = ["smoltcp/socket-udp"]
|
||||||
tcp = ["smoltcp/socket-tcp"]
|
tcp = ["smoltcp/socket-tcp"]
|
||||||
dns = ["smoltcp/socket-dns", "smoltcp/proto-dns"]
|
dns = ["smoltcp/socket-dns", "smoltcp/proto-dns"]
|
||||||
dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"]
|
dhcpv4 = ["proto-ipv4", "medium-ethernet", "smoltcp/socket-dhcpv4"]
|
||||||
|
proto-ipv4 = ["smoltcp/proto-ipv4"]
|
||||||
proto-ipv6 = ["smoltcp/proto-ipv6"]
|
proto-ipv6 = ["smoltcp/proto-ipv6"]
|
||||||
medium-ethernet = ["smoltcp/medium-ethernet"]
|
medium-ethernet = ["smoltcp/medium-ethernet"]
|
||||||
medium-ip = ["smoltcp/medium-ip"]
|
medium-ip = ["smoltcp/medium-ip"]
|
||||||
@ -38,7 +39,6 @@ defmt = { version = "0.3", optional = true }
|
|||||||
log = { version = "0.4.14", optional = true }
|
log = { version = "0.4.14", optional = true }
|
||||||
|
|
||||||
smoltcp = { version = "0.9.0", default-features = false, features = [
|
smoltcp = { version = "0.9.0", default-features = false, features = [
|
||||||
"proto-ipv4",
|
|
||||||
"socket",
|
"socket",
|
||||||
"async",
|
"async",
|
||||||
]}
|
]}
|
||||||
|
@ -59,7 +59,10 @@ where
|
|||||||
smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4);
|
smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4);
|
||||||
smolcaps.checksum.tcp = convert(caps.checksum.tcp);
|
smolcaps.checksum.tcp = convert(caps.checksum.tcp);
|
||||||
smolcaps.checksum.udp = convert(caps.checksum.udp);
|
smolcaps.checksum.udp = convert(caps.checksum.udp);
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
{
|
||||||
smolcaps.checksum.icmpv4 = convert(caps.checksum.icmpv4);
|
smolcaps.checksum.icmpv4 = convert(caps.checksum.icmpv4);
|
||||||
|
}
|
||||||
#[cfg(feature = "proto-ipv6")]
|
#[cfg(feature = "proto-ipv6")]
|
||||||
{
|
{
|
||||||
smolcaps.checksum.icmpv6 = convert(caps.checksum.icmpv6);
|
smolcaps.checksum.icmpv6 = convert(caps.checksum.icmpv6);
|
||||||
|
@ -88,6 +88,7 @@ where
|
|||||||
let addrs = self.query(host, qtype).await?;
|
let addrs = self.query(host, qtype).await?;
|
||||||
if let Some(first) = addrs.get(0) {
|
if let Some(first) = addrs.get(0) {
|
||||||
Ok(match first {
|
Ok(match first {
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
IpAddress::Ipv4(addr) => IpAddr::V4(addr.0.into()),
|
IpAddress::Ipv4(addr) => IpAddr::V4(addr.0.into()),
|
||||||
#[cfg(feature = "proto-ipv6")]
|
#[cfg(feature = "proto-ipv6")]
|
||||||
IpAddress::Ipv6(addr) => IpAddr::V6(addr.0.into()),
|
IpAddress::Ipv6(addr) => IpAddr::V6(addr.0.into()),
|
||||||
|
@ -34,7 +34,9 @@ use smoltcp::socket::dhcpv4::{self, RetryConfig};
|
|||||||
pub use smoltcp::wire::IpListenEndpoint;
|
pub use smoltcp::wire::IpListenEndpoint;
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
pub use smoltcp::wire::{EthernetAddress, HardwareAddress};
|
pub use smoltcp::wire::{EthernetAddress, HardwareAddress};
|
||||||
pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr};
|
pub use smoltcp::wire::{IpAddress, IpCidr};
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
pub use smoltcp::wire::{Ipv4Address, Ipv4Cidr};
|
||||||
#[cfg(feature = "proto-ipv6")]
|
#[cfg(feature = "proto-ipv6")]
|
||||||
pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr};
|
pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr};
|
||||||
|
|
||||||
@ -67,8 +69,9 @@ impl<const SOCK: usize> StackResources<SOCK> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Static IP address configuration.
|
/// Static IP address configuration.
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct StaticConfig {
|
pub struct StaticConfigV4 {
|
||||||
/// IP address and subnet mask.
|
/// IP address and subnet mask.
|
||||||
pub address: Ipv4Cidr,
|
pub address: Ipv4Cidr,
|
||||||
/// Default gateway.
|
/// Default gateway.
|
||||||
@ -77,6 +80,18 @@ pub struct StaticConfig {
|
|||||||
pub dns_servers: Vec<Ipv4Address, 3>,
|
pub dns_servers: Vec<Ipv4Address, 3>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Static IPv6 address configuration
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct StaticConfigV6 {
|
||||||
|
/// IP address and subnet mask.
|
||||||
|
pub address: Ipv6Cidr,
|
||||||
|
/// Default gateway.
|
||||||
|
pub gateway: Option<Ipv6Address>,
|
||||||
|
/// DNS servers.
|
||||||
|
pub dns_servers: Vec<Ipv6Address, 3>,
|
||||||
|
}
|
||||||
|
|
||||||
/// DHCP configuration.
|
/// DHCP configuration.
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@ -112,12 +127,71 @@ impl Default for DhcpConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Network stack configuration.
|
/// Network stack configuration.
|
||||||
pub enum Config {
|
pub struct Config {
|
||||||
/// Use a static IP address configuration.
|
/// IPv4 configuration
|
||||||
Static(StaticConfig),
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
pub ipv4: ConfigV4,
|
||||||
|
/// IPv6 configuration
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
pub ipv6: ConfigV6,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
/// IPv4 configuration with static addressing.
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
pub fn ipv4_static(config: StaticConfigV4) -> Self {
|
||||||
|
Self {
|
||||||
|
ipv4: ConfigV4::Static(config),
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
ipv6: ConfigV6::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// IPv6 configuration with static addressing.
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
pub fn ipv6_static(config: StaticConfigV6) -> Self {
|
||||||
|
Self {
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
ipv4: ConfigV4::None,
|
||||||
|
ipv6: ConfigV6::Static(config),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// IPv6 configuration with dynamic addressing.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```rust
|
||||||
|
/// let _cfg = Config::dhcpv4(Default::default());
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "dhcpv4")]
|
||||||
|
pub fn dhcpv4(config: DhcpConfig) -> Self {
|
||||||
|
Self {
|
||||||
|
ipv4: ConfigV4::Dhcp(config),
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
ipv6: ConfigV6::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Network stack IPv4 configuration.
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
pub enum ConfigV4 {
|
||||||
|
/// Use a static IPv4 address configuration.
|
||||||
|
Static(StaticConfigV4),
|
||||||
/// Use DHCP to obtain an IP address configuration.
|
/// Use DHCP to obtain an IP address configuration.
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
Dhcp(DhcpConfig),
|
Dhcp(DhcpConfig),
|
||||||
|
/// Do not configure IPv6.
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Network stack IPv6 configuration.
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
pub enum ConfigV6 {
|
||||||
|
/// Use a static IPv6 address configuration.
|
||||||
|
Static(StaticConfigV6),
|
||||||
|
/// Do not configure IPv6.
|
||||||
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A network stack.
|
/// A network stack.
|
||||||
@ -131,7 +205,10 @@ pub struct Stack<D: Driver> {
|
|||||||
struct Inner<D: Driver> {
|
struct Inner<D: Driver> {
|
||||||
device: D,
|
device: D,
|
||||||
link_up: bool,
|
link_up: bool,
|
||||||
config: Option<StaticConfig>,
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
static_v4: Option<StaticConfigV4>,
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
static_v6: Option<StaticConfigV6>,
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
dhcp_socket: Option<SocketHandle>,
|
dhcp_socket: Option<SocketHandle>,
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
@ -187,7 +264,10 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
let mut inner = Inner {
|
let mut inner = Inner {
|
||||||
device,
|
device,
|
||||||
link_up: false,
|
link_up: false,
|
||||||
config: None,
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
static_v4: None,
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
static_v6: None,
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
dhcp_socket: None,
|
dhcp_socket: None,
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
@ -199,17 +279,26 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
dns_waker: WakerRegistration::new(),
|
dns_waker: WakerRegistration::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
match config {
|
#[cfg(feature = "proto-ipv4")]
|
||||||
Config::Static(config) => {
|
match config.ipv4 {
|
||||||
inner.apply_config(&mut socket, config);
|
ConfigV4::Static(config) => {
|
||||||
|
inner.apply_config_v4(&mut socket, config);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
Config::Dhcp(config) => {
|
ConfigV4::Dhcp(config) => {
|
||||||
let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new();
|
let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new();
|
||||||
inner.apply_dhcp_config(&mut dhcp_socket, config);
|
inner.apply_dhcp_config(&mut dhcp_socket, config);
|
||||||
let handle = socket.sockets.add(dhcp_socket);
|
let handle = socket.sockets.add(dhcp_socket);
|
||||||
inner.dhcp_socket = Some(handle);
|
inner.dhcp_socket = Some(handle);
|
||||||
}
|
}
|
||||||
|
ConfigV4::None => {}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
match config.ipv6 {
|
||||||
|
ConfigV6::Static(config) => {
|
||||||
|
inner.apply_config_v6(&mut socket, config);
|
||||||
|
}
|
||||||
|
ConfigV6::None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -239,12 +328,40 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
/// Get whether the network stack has a valid IP configuration.
|
/// Get whether the network stack has a valid IP configuration.
|
||||||
/// This is true if the network stack has a static IP configuration or if DHCP has completed
|
/// This is true if the network stack has a static IP configuration or if DHCP has completed
|
||||||
pub fn is_config_up(&self) -> bool {
|
pub fn is_config_up(&self) -> bool {
|
||||||
self.with(|_s, i| i.config.is_some())
|
let v4_up;
|
||||||
|
let v6_up;
|
||||||
|
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
{
|
||||||
|
v4_up = self.config_v4().is_some();
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "proto-ipv4"))]
|
||||||
|
{
|
||||||
|
v4_up = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current IP configuration.
|
#[cfg(feature = "proto-ipv6")]
|
||||||
pub fn config(&self) -> Option<StaticConfig> {
|
{
|
||||||
self.with(|_s, i| i.config.clone())
|
v6_up = self.config_v6().is_some();
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "proto-ipv6"))]
|
||||||
|
{
|
||||||
|
v6_up = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
v4_up || v6_up
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current IPv4 configuration.
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
pub fn config_v4(&self) -> Option<StaticConfigV4> {
|
||||||
|
self.with(|_s, i| i.static_v4.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current IPv6 configuration.
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
pub fn config_v6(&self) -> Option<StaticConfigV6> {
|
||||||
|
self.with(|_s, i| i.static_v6.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the network stack.
|
/// Run the network stack.
|
||||||
@ -264,6 +381,7 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> {
|
pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> {
|
||||||
// For A and AAAA queries we try detect whether `name` is just an IP address
|
// For A and AAAA queries we try detect whether `name` is just an IP address
|
||||||
match qtype {
|
match qtype {
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
dns::DnsQueryType::A => {
|
dns::DnsQueryType::A => {
|
||||||
if let Ok(ip) = name.parse().map(IpAddress::Ipv4) {
|
if let Ok(ip) = name.parse().map(IpAddress::Ipv4) {
|
||||||
return Ok([ip].into_iter().collect());
|
return Ok([ip].into_iter().collect());
|
||||||
@ -374,7 +492,8 @@ impl SocketStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Driver + 'static> Inner<D> {
|
impl<D: Driver + 'static> Inner<D> {
|
||||||
fn apply_config(&mut self, s: &mut SocketStack, config: StaticConfig) {
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
fn apply_config_v4(&mut self, s: &mut SocketStack, config: StaticConfigV4) {
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let medium = self.device.capabilities().medium;
|
let medium = self.device.capabilities().medium;
|
||||||
|
|
||||||
@ -403,14 +522,86 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
debug!(" DNS server {}: {}", i, s);
|
debug!(" DNS server {}: {}", i, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.static_v4 = Some(config);
|
||||||
|
|
||||||
#[cfg(feature = "dns")]
|
#[cfg(feature = "dns")]
|
||||||
{
|
{
|
||||||
let socket = s.sockets.get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket);
|
self.update_dns_servers(s)
|
||||||
let servers: Vec<IpAddress, 3> = config.dns_servers.iter().map(|c| IpAddress::Ipv4(*c)).collect();
|
}
|
||||||
socket.update_servers(&servers[..]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config = Some(config)
|
/// Replaces the current IPv6 static configuration with a newly supplied config.
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
fn apply_config_v6(&mut self, s: &mut SocketStack, config: StaticConfigV6) {
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
let medium = self.device.capabilities().medium;
|
||||||
|
|
||||||
|
debug!("Acquired IPv6 configuration:");
|
||||||
|
|
||||||
|
debug!(" IP address: {}", config.address);
|
||||||
|
s.iface.update_ip_addrs(|addrs| {
|
||||||
|
if addrs.is_empty() {
|
||||||
|
addrs.push(IpCidr::Ipv6(config.address)).unwrap();
|
||||||
|
} else {
|
||||||
|
addrs[0] = IpCidr::Ipv6(config.address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
#[cfg(feature = "medium-ethernet")]
|
||||||
|
if Medium::Ethernet == medium {
|
||||||
|
if let Some(gateway) = config.gateway {
|
||||||
|
debug!(" Default gateway: {}", gateway);
|
||||||
|
s.iface.routes_mut().add_default_ipv6_route(gateway).unwrap();
|
||||||
|
} else {
|
||||||
|
debug!(" Default gateway: None");
|
||||||
|
s.iface.routes_mut().remove_default_ipv6_route();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i, s) in config.dns_servers.iter().enumerate() {
|
||||||
|
debug!(" DNS server {}: {}", i, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.static_v6 = Some(config);
|
||||||
|
|
||||||
|
#[cfg(feature = "dns")]
|
||||||
|
{
|
||||||
|
self.update_dns_servers(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dns")]
|
||||||
|
fn update_dns_servers(&mut self, s: &mut SocketStack) {
|
||||||
|
let socket = s.sockets.get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket);
|
||||||
|
|
||||||
|
let servers_v4;
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
{
|
||||||
|
servers_v4 = self
|
||||||
|
.static_v4
|
||||||
|
.iter()
|
||||||
|
.flat_map(|cfg| cfg.dns_servers.iter().map(|c| IpAddress::Ipv4(*c)));
|
||||||
|
};
|
||||||
|
#[cfg(not(feature = "proto-ipv4"))]
|
||||||
|
{
|
||||||
|
servers_v4 = core::iter::empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
let servers_v6;
|
||||||
|
#[cfg(feature = "proto-ipv6")]
|
||||||
|
{
|
||||||
|
servers_v6 = self
|
||||||
|
.static_v6
|
||||||
|
.iter()
|
||||||
|
.flat_map(|cfg| cfg.dns_servers.iter().map(|c| IpAddress::Ipv6(*c)));
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "proto-ipv6"))]
|
||||||
|
{
|
||||||
|
servers_v6 = core::iter::empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer the v6 DNS servers over the v4 servers
|
||||||
|
let servers: Vec<IpAddress, 6> = servers_v6.chain(servers_v4).collect();
|
||||||
|
socket.update_servers(&servers[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
@ -430,9 +621,15 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear());
|
s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear());
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
{
|
||||||
s.iface.routes_mut().remove_default_ipv4_route();
|
s.iface.routes_mut().remove_default_ipv4_route();
|
||||||
}
|
}
|
||||||
self.config = None
|
}
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
|
{
|
||||||
|
self.static_v4 = None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
||||||
@ -470,12 +667,12 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
None => {}
|
None => {}
|
||||||
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s),
|
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s),
|
||||||
Some(dhcpv4::Event::Configured(config)) => {
|
Some(dhcpv4::Event::Configured(config)) => {
|
||||||
let config = StaticConfig {
|
let config = StaticConfigV4 {
|
||||||
address: config.address,
|
address: config.address,
|
||||||
gateway: config.router,
|
gateway: config.router,
|
||||||
dns_servers: config.dns_servers,
|
dns_servers: config.dns_servers,
|
||||||
};
|
};
|
||||||
self.apply_config(s, config)
|
self.apply_config_v4(s, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if old_link_up {
|
} else if old_link_up {
|
||||||
|
@ -480,7 +480,10 @@ pub mod client {
|
|||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
let addr: crate::IpAddress = match remote.ip() {
|
let addr: crate::IpAddress = match remote.ip() {
|
||||||
|
#[cfg(feature = "proto-ipv4")]
|
||||||
IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())),
|
IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())),
|
||||||
|
#[cfg(not(feature = "proto-ipv4"))]
|
||||||
|
IpAddr::V4(_) => panic!("ipv4 support not enabled"),
|
||||||
#[cfg(feature = "proto-ipv6")]
|
#[cfg(feature = "proto-ipv6")]
|
||||||
IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())),
|
IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())),
|
||||||
#[cfg(not(feature = "proto-ipv6"))]
|
#[cfg(not(feature = "proto-ipv6"))]
|
||||||
|
@ -97,12 +97,12 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
// let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
//});
|
// });
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
let mut rng = Rng::new(p.RNG, Irqs);
|
let mut rng = Rng::new(p.RNG, Irqs);
|
||||||
|
@ -64,7 +64,7 @@ async fn main(spawner: Spawner) {
|
|||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*make_static!(Stack::new(
|
let stack = &*make_static!(Stack::new(
|
||||||
device,
|
device,
|
||||||
embassy_net::Config::Dhcp(Default::default()),
|
embassy_net::Config::dhcpv4(Default::default()),
|
||||||
make_static!(StackResources::<3>::new()),
|
make_static!(StackResources::<3>::new()),
|
||||||
seed
|
seed
|
||||||
));
|
));
|
||||||
@ -120,9 +120,9 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig {
|
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
|
||||||
loop {
|
loop {
|
||||||
if let Some(config) = stack.config() {
|
if let Some(config) = stack.config_v4() {
|
||||||
return config.clone();
|
return config.clone();
|
||||||
}
|
}
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
|
@ -67,7 +67,7 @@ async fn main(spawner: Spawner) {
|
|||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*make_static!(Stack::new(
|
let stack = &*make_static!(Stack::new(
|
||||||
device,
|
device,
|
||||||
embassy_net::Config::Dhcp(Default::default()),
|
embassy_net::Config::dhcpv4(Default::default()),
|
||||||
make_static!(StackResources::<2>::new()),
|
make_static!(StackResources::<2>::new()),
|
||||||
seed
|
seed
|
||||||
));
|
));
|
||||||
@ -108,9 +108,9 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig {
|
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
|
||||||
loop {
|
loop {
|
||||||
if let Some(config) = stack.config() {
|
if let Some(config) = stack.config_v4() {
|
||||||
return config.clone();
|
return config.clone();
|
||||||
}
|
}
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
|
@ -65,7 +65,7 @@ async fn main(spawner: Spawner) {
|
|||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*make_static!(Stack::new(
|
let stack = &*make_static!(Stack::new(
|
||||||
device,
|
device,
|
||||||
embassy_net::Config::Dhcp(Default::default()),
|
embassy_net::Config::dhcpv4(Default::default()),
|
||||||
make_static!(StackResources::<2>::new()),
|
make_static!(StackResources::<2>::new()),
|
||||||
seed
|
seed
|
||||||
));
|
));
|
||||||
@ -116,9 +116,9 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig {
|
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
|
||||||
loop {
|
loop {
|
||||||
if let Some(config) = stack.config() {
|
if let Some(config) = stack.config_v4() {
|
||||||
return config.clone();
|
return config.clone();
|
||||||
}
|
}
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
|
@ -62,7 +62,7 @@ async fn main(spawner: Spawner) {
|
|||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*make_static!(Stack::new(
|
let stack = &*make_static!(Stack::new(
|
||||||
device,
|
device,
|
||||||
embassy_net::Config::Dhcp(Default::default()),
|
embassy_net::Config::dhcpv4(Default::default()),
|
||||||
make_static!(StackResources::<2>::new()),
|
make_static!(StackResources::<2>::new()),
|
||||||
seed
|
seed
|
||||||
));
|
));
|
||||||
@ -95,9 +95,9 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig {
|
async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 {
|
||||||
loop {
|
loop {
|
||||||
if let Some(config) = stack.config() {
|
if let Some(config) = stack.config_v4() {
|
||||||
return config.clone();
|
return config.clone();
|
||||||
}
|
}
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
|
@ -86,8 +86,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -62,7 +62,7 @@ async fn main(spawner: Spawner) {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Use a link-local address for communication without DHCP server
|
// Use a link-local address for communication without DHCP server
|
||||||
let config = Config::Static(embassy_net::StaticConfig {
|
let config = Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16),
|
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16),
|
||||||
dns_servers: heapless::Vec::new(),
|
dns_servers: heapless::Vec::new(),
|
||||||
gateway: None,
|
gateway: None,
|
||||||
|
@ -61,8 +61,8 @@ async fn main(spawner: Spawner) {
|
|||||||
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let config = Config::Dhcp(Default::default());
|
let config = Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::Config {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
// gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
|
@ -42,13 +42,13 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
Config::Static(embassy_net::StaticConfig {
|
Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
dns_servers: Vec::new(),
|
dns_servers: Vec::new(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Config::Dhcp(Default::default())
|
Config::dhcpv4(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
|
@ -40,14 +40,14 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
Config::Static(embassy_net::StaticConfig {
|
Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24),
|
||||||
dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()])
|
dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()])
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 100)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 100)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Config::Dhcp(Default::default())
|
Config::dhcpv4(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
|
@ -38,13 +38,13 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
Config::Static(embassy_net::StaticConfig {
|
Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
dns_servers: Vec::new(),
|
dns_servers: Vec::new(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Config::Dhcp(Default::default())
|
Config::dhcpv4(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
|
@ -53,13 +53,13 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
Config::Static(embassy_net::StaticConfig {
|
Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
dns_servers: Vec::new(),
|
dns_servers: Vec::new(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Config::Dhcp(Default::default())
|
Config::dhcpv4(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
|
@ -94,8 +94,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -62,8 +62,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -81,8 +81,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -63,8 +63,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -64,8 +64,8 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::StaticConfig(embassy_net::Config {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -91,8 +91,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::Config::Dhcp(Default::default());
|
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
|
@ -63,7 +63,7 @@ async fn main(spawner: Spawner) {
|
|||||||
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let config = Config::Dhcp(Default::default());
|
let config = Config::dhcpv4(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::Config {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
@ -93,7 +93,7 @@ async fn main(spawner: Spawner) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Waiting for DHCP up...");
|
info!("Waiting for DHCP up...");
|
||||||
while stack.config().is_none() {
|
while stack.config_v4().is_none() {
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
info!("IP addressing up!");
|
info!("IP addressing up!");
|
||||||
@ -115,9 +115,9 @@ const WIFI_NETWORK: &str = "EmbassyTest";
|
|||||||
const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
|
const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud";
|
||||||
|
|
||||||
const TEST_DURATION: usize = 10;
|
const TEST_DURATION: usize = 10;
|
||||||
const TEST_EXPECTED_DOWNLOAD_KBPS: usize = 500;
|
const TEST_EXPECTED_DOWNLOAD_KBPS: usize = 300;
|
||||||
const TEST_EXPECTED_UPLOAD_KBPS: usize = 500;
|
const TEST_EXPECTED_UPLOAD_KBPS: usize = 300;
|
||||||
const TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS: usize = 400;
|
const TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS: usize = 300;
|
||||||
const RX_BUFFER_SIZE: usize = 4096;
|
const RX_BUFFER_SIZE: usize = 4096;
|
||||||
const TX_BUFFER_SIZE: usize = 4096;
|
const TX_BUFFER_SIZE: usize = 4096;
|
||||||
const SERVER_ADDRESS: Ipv4Address = Ipv4Address::new(192, 168, 2, 2);
|
const SERVER_ADDRESS: Ipv4Address = Ipv4Address::new(192, 168, 2, 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user