diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-06-08 19:13:46 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-06-08 19:13:46 +0000 |
| commit | 2e0bc71c866d1844b2f069090861ca678576c7a1 (patch) | |
| tree | 7e358326645dd0b8f3fbf95038d2f6128271de4e | |
| parent | b68cf6c5c81d2bdc373e45c6adeedb5fa1241463 (diff) | |
| parent | 3dde01597a7861817ee52fef6ea4b5732a77debc (diff) | |
Merge pull request #1535 from rubdos/v4-optional
Add IPv6 to Embassy net, make IPv4 optional
26 files changed, 289 insertions, 75 deletions
| @@ -25,11 +25,19 @@ cargo batch \ | |||
| 25 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ | 25 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ |
| 26 | --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ | 26 | --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ |
| 27 | --- 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 \ | 27 | --- 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 \ |
| 28 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,medium-ethernet \ | 28 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ |
| 29 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ | 29 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ |
| 30 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \ | 30 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \ |
| 31 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,nightly \ | 31 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,nightly \ |
| 32 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits,nightly \ | 32 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits,nightly \ |
| 33 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \ | ||
| 34 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits \ | ||
| 35 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,nightly \ | ||
| 36 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits,nightly \ | ||
| 37 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet \ | ||
| 38 | --- 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 \ | ||
| 39 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,proto-ipv6,medium-ethernet,nightly \ | ||
| 40 | --- 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 \ | ||
| 33 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52805,gpiote,time-driver-rtc1 \ | 41 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52805,gpiote,time-driver-rtc1 \ |
| 34 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52810,gpiote,time-driver-rtc1 \ | 42 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52810,gpiote,time-driver-rtc1 \ |
| 35 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52811,gpiote,time-driver-rtc1 \ | 43 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nightly,nrf52811,gpiote,time-driver-rtc1 \ |
| @@ -160,4 +168,4 @@ if [[ -z "${TELEPROBE_TOKEN-}" ]]; then | |||
| 160 | exit | 168 | exit |
| 161 | fi | 169 | fi |
| 162 | 170 | ||
| 163 | teleprobe client run -r out/tests \ No newline at end of file | 171 | teleprobe client run -r out/tests |
diff --git a/ci_stable.sh b/ci_stable.sh index a67087ffb..daae98961 100755 --- a/ci_stable.sh +++ b/ci_stable.sh | |||
| @@ -14,9 +14,11 @@ cargo batch \ | |||
| 14 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \ | 14 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features log \ |
| 15 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \ | 15 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features defmt \ |
| 16 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \ | 16 | --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features defmt \ |
| 17 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,medium-ethernet \ | 17 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \ |
| 18 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ | 18 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \ |
| 19 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \ | 19 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,unstable-traits \ |
| 20 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet \ | ||
| 21 | --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv6,medium-ethernet,unstable-traits \ | ||
| 20 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time-driver-rtc1 \ | 22 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52805,gpiote,time-driver-rtc1 \ |
| 21 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time-driver-rtc1 \ | 23 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52810,gpiote,time-driver-rtc1 \ |
| 22 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time-driver-rtc1 \ | 24 | --- build --release --manifest-path embassy-nrf/Cargo.toml --target thumbv7em-none-eabi --features nrf52811,gpiote,time-driver-rtc1 \ |
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 0a47c5d94..4ac572577 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml | |||
| @@ -26,7 +26,8 @@ unstable-traits = [] | |||
| 26 | udp = ["smoltcp/socket-udp"] | 26 | udp = ["smoltcp/socket-udp"] |
| 27 | tcp = ["smoltcp/socket-tcp"] | 27 | tcp = ["smoltcp/socket-tcp"] |
| 28 | dns = ["smoltcp/socket-dns", "smoltcp/proto-dns"] | 28 | dns = ["smoltcp/socket-dns", "smoltcp/proto-dns"] |
| 29 | dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] | 29 | dhcpv4 = ["proto-ipv4", "medium-ethernet", "smoltcp/socket-dhcpv4"] |
| 30 | proto-ipv4 = ["smoltcp/proto-ipv4"] | ||
| 30 | proto-ipv6 = ["smoltcp/proto-ipv6"] | 31 | proto-ipv6 = ["smoltcp/proto-ipv6"] |
| 31 | medium-ethernet = ["smoltcp/medium-ethernet"] | 32 | medium-ethernet = ["smoltcp/medium-ethernet"] |
| 32 | medium-ip = ["smoltcp/medium-ip"] | 33 | medium-ip = ["smoltcp/medium-ip"] |
| @@ -38,7 +39,6 @@ defmt = { version = "0.3", optional = true } | |||
| 38 | log = { version = "0.4.14", optional = true } | 39 | log = { version = "0.4.14", optional = true } |
| 39 | 40 | ||
| 40 | smoltcp = { version = "0.9.0", default-features = false, features = [ | 41 | smoltcp = { version = "0.9.0", default-features = false, features = [ |
| 41 | "proto-ipv4", | ||
| 42 | "socket", | 42 | "socket", |
| 43 | "async", | 43 | "async", |
| 44 | ]} | 44 | ]} |
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 5daa00544..583cdc87f 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -59,7 +59,10 @@ where | |||
| 59 | smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4); | 59 | smolcaps.checksum.ipv4 = convert(caps.checksum.ipv4); |
| 60 | smolcaps.checksum.tcp = convert(caps.checksum.tcp); | 60 | smolcaps.checksum.tcp = convert(caps.checksum.tcp); |
| 61 | smolcaps.checksum.udp = convert(caps.checksum.udp); | 61 | smolcaps.checksum.udp = convert(caps.checksum.udp); |
| 62 | smolcaps.checksum.icmpv4 = convert(caps.checksum.icmpv4); | 62 | #[cfg(feature = "proto-ipv4")] |
| 63 | { | ||
| 64 | smolcaps.checksum.icmpv4 = convert(caps.checksum.icmpv4); | ||
| 65 | } | ||
| 63 | #[cfg(feature = "proto-ipv6")] | 66 | #[cfg(feature = "proto-ipv6")] |
| 64 | { | 67 | { |
| 65 | smolcaps.checksum.icmpv6 = convert(caps.checksum.icmpv6); | 68 | smolcaps.checksum.icmpv6 = convert(caps.checksum.icmpv6); |
diff --git a/embassy-net/src/dns.rs b/embassy-net/src/dns.rs index 3fd235b2c..94f75f108 100644 --- a/embassy-net/src/dns.rs +++ b/embassy-net/src/dns.rs | |||
| @@ -88,6 +88,7 @@ where | |||
| 88 | let addrs = self.query(host, qtype).await?; | 88 | let addrs = self.query(host, qtype).await?; |
| 89 | if let Some(first) = addrs.get(0) { | 89 | if let Some(first) = addrs.get(0) { |
| 90 | Ok(match first { | 90 | Ok(match first { |
| 91 | #[cfg(feature = "proto-ipv4")] | ||
| 91 | IpAddress::Ipv4(addr) => IpAddr::V4(addr.0.into()), | 92 | IpAddress::Ipv4(addr) => IpAddr::V4(addr.0.into()), |
| 92 | #[cfg(feature = "proto-ipv6")] | 93 | #[cfg(feature = "proto-ipv6")] |
| 93 | IpAddress::Ipv6(addr) => IpAddr::V6(addr.0.into()), | 94 | IpAddress::Ipv6(addr) => IpAddr::V6(addr.0.into()), |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index bccbad521..7e8f765f9 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -34,7 +34,9 @@ use smoltcp::socket::dhcpv4::{self, RetryConfig}; | |||
| 34 | pub use smoltcp::wire::IpListenEndpoint; | 34 | pub use smoltcp::wire::IpListenEndpoint; |
| 35 | #[cfg(feature = "medium-ethernet")] | 35 | #[cfg(feature = "medium-ethernet")] |
| 36 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; | 36 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; |
| 37 | pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | 37 | pub use smoltcp::wire::{IpAddress, IpCidr}; |
| 38 | #[cfg(feature = "proto-ipv4")] | ||
| 39 | pub use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; | ||
| 38 | #[cfg(feature = "proto-ipv6")] | 40 | #[cfg(feature = "proto-ipv6")] |
| 39 | pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; | 41 | pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; |
| 40 | 42 | ||
| @@ -67,8 +69,9 @@ impl<const SOCK: usize> StackResources<SOCK> { | |||
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | /// Static IP address configuration. | 71 | /// Static IP address configuration. |
| 72 | #[cfg(feature = "proto-ipv4")] | ||
| 70 | #[derive(Debug, Clone, PartialEq, Eq)] | 73 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 71 | pub struct StaticConfig { | 74 | pub struct StaticConfigV4 { |
| 72 | /// IP address and subnet mask. | 75 | /// IP address and subnet mask. |
| 73 | pub address: Ipv4Cidr, | 76 | pub address: Ipv4Cidr, |
| 74 | /// Default gateway. | 77 | /// Default gateway. |
| @@ -77,6 +80,18 @@ pub struct StaticConfig { | |||
| 77 | pub dns_servers: Vec<Ipv4Address, 3>, | 80 | pub dns_servers: Vec<Ipv4Address, 3>, |
| 78 | } | 81 | } |
| 79 | 82 | ||
| 83 | /// Static IPv6 address configuration | ||
| 84 | #[cfg(feature = "proto-ipv6")] | ||
| 85 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
| 86 | pub struct StaticConfigV6 { | ||
| 87 | /// IP address and subnet mask. | ||
| 88 | pub address: Ipv6Cidr, | ||
| 89 | /// Default gateway. | ||
| 90 | pub gateway: Option<Ipv6Address>, | ||
| 91 | /// DNS servers. | ||
| 92 | pub dns_servers: Vec<Ipv6Address, 3>, | ||
| 93 | } | ||
| 94 | |||
| 80 | /// DHCP configuration. | 95 | /// DHCP configuration. |
| 81 | #[cfg(feature = "dhcpv4")] | 96 | #[cfg(feature = "dhcpv4")] |
| 82 | #[derive(Debug, Clone, PartialEq, Eq)] | 97 | #[derive(Debug, Clone, PartialEq, Eq)] |
| @@ -112,12 +127,71 @@ impl Default for DhcpConfig { | |||
| 112 | } | 127 | } |
| 113 | 128 | ||
| 114 | /// Network stack configuration. | 129 | /// Network stack configuration. |
| 115 | pub enum Config { | 130 | pub struct Config { |
| 116 | /// Use a static IP address configuration. | 131 | /// IPv4 configuration |
| 117 | Static(StaticConfig), | 132 | #[cfg(feature = "proto-ipv4")] |
| 133 | pub ipv4: ConfigV4, | ||
| 134 | /// IPv6 configuration | ||
| 135 | #[cfg(feature = "proto-ipv6")] | ||
| 136 | pub ipv6: ConfigV6, | ||
| 137 | } | ||
| 138 | |||
| 139 | impl Config { | ||
| 140 | /// IPv4 configuration with static addressing. | ||
| 141 | #[cfg(feature = "proto-ipv4")] | ||
| 142 | pub fn ipv4_static(config: StaticConfigV4) -> Self { | ||
| 143 | Self { | ||
| 144 | ipv4: ConfigV4::Static(config), | ||
| 145 | #[cfg(feature = "proto-ipv6")] | ||
| 146 | ipv6: ConfigV6::None, | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | /// IPv6 configuration with static addressing. | ||
| 151 | #[cfg(feature = "proto-ipv6")] | ||
| 152 | pub fn ipv6_static(config: StaticConfigV6) -> Self { | ||
| 153 | Self { | ||
| 154 | #[cfg(feature = "proto-ipv4")] | ||
| 155 | ipv4: ConfigV4::None, | ||
| 156 | ipv6: ConfigV6::Static(config), | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | /// IPv6 configuration with dynamic addressing. | ||
| 161 | /// | ||
| 162 | /// # Example | ||
| 163 | /// ```rust | ||
| 164 | /// let _cfg = Config::dhcpv4(Default::default()); | ||
| 165 | /// ``` | ||
| 166 | #[cfg(feature = "dhcpv4")] | ||
| 167 | pub fn dhcpv4(config: DhcpConfig) -> Self { | ||
| 168 | Self { | ||
| 169 | ipv4: ConfigV4::Dhcp(config), | ||
| 170 | #[cfg(feature = "proto-ipv6")] | ||
| 171 | ipv6: ConfigV6::None, | ||
| 172 | } | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | /// Network stack IPv4 configuration. | ||
| 177 | #[cfg(feature = "proto-ipv4")] | ||
| 178 | pub enum ConfigV4 { | ||
| 179 | /// Use a static IPv4 address configuration. | ||
| 180 | Static(StaticConfigV4), | ||
| 118 | /// Use DHCP to obtain an IP address configuration. | 181 | /// Use DHCP to obtain an IP address configuration. |
| 119 | #[cfg(feature = "dhcpv4")] | 182 | #[cfg(feature = "dhcpv4")] |
| 120 | Dhcp(DhcpConfig), | 183 | Dhcp(DhcpConfig), |
| 184 | /// Do not configure IPv6. | ||
| 185 | None, | ||
| 186 | } | ||
| 187 | |||
| 188 | /// Network stack IPv6 configuration. | ||
| 189 | #[cfg(feature = "proto-ipv6")] | ||
| 190 | pub enum ConfigV6 { | ||
| 191 | /// Use a static IPv6 address configuration. | ||
| 192 | Static(StaticConfigV6), | ||
| 193 | /// Do not configure IPv6. | ||
| 194 | None, | ||
| 121 | } | 195 | } |
| 122 | 196 | ||
| 123 | /// A network stack. | 197 | /// A network stack. |
| @@ -131,7 +205,10 @@ pub struct Stack<D: Driver> { | |||
| 131 | struct Inner<D: Driver> { | 205 | struct Inner<D: Driver> { |
| 132 | device: D, | 206 | device: D, |
| 133 | link_up: bool, | 207 | link_up: bool, |
| 134 | config: Option<StaticConfig>, | 208 | #[cfg(feature = "proto-ipv4")] |
| 209 | static_v4: Option<StaticConfigV4>, | ||
| 210 | #[cfg(feature = "proto-ipv6")] | ||
| 211 | static_v6: Option<StaticConfigV6>, | ||
| 135 | #[cfg(feature = "dhcpv4")] | 212 | #[cfg(feature = "dhcpv4")] |
| 136 | dhcp_socket: Option<SocketHandle>, | 213 | dhcp_socket: Option<SocketHandle>, |
| 137 | #[cfg(feature = "dns")] | 214 | #[cfg(feature = "dns")] |
| @@ -187,7 +264,10 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 187 | let mut inner = Inner { | 264 | let mut inner = Inner { |
| 188 | device, | 265 | device, |
| 189 | link_up: false, | 266 | link_up: false, |
| 190 | config: None, | 267 | #[cfg(feature = "proto-ipv4")] |
| 268 | static_v4: None, | ||
| 269 | #[cfg(feature = "proto-ipv6")] | ||
| 270 | static_v6: None, | ||
| 191 | #[cfg(feature = "dhcpv4")] | 271 | #[cfg(feature = "dhcpv4")] |
| 192 | dhcp_socket: None, | 272 | dhcp_socket: None, |
| 193 | #[cfg(feature = "dns")] | 273 | #[cfg(feature = "dns")] |
| @@ -199,17 +279,26 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 199 | dns_waker: WakerRegistration::new(), | 279 | dns_waker: WakerRegistration::new(), |
| 200 | }; | 280 | }; |
| 201 | 281 | ||
| 202 | match config { | 282 | #[cfg(feature = "proto-ipv4")] |
| 203 | Config::Static(config) => { | 283 | match config.ipv4 { |
| 204 | inner.apply_config(&mut socket, config); | 284 | ConfigV4::Static(config) => { |
| 285 | inner.apply_config_v4(&mut socket, config); | ||
| 205 | } | 286 | } |
| 206 | #[cfg(feature = "dhcpv4")] | 287 | #[cfg(feature = "dhcpv4")] |
| 207 | Config::Dhcp(config) => { | 288 | ConfigV4::Dhcp(config) => { |
| 208 | let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new(); | 289 | let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new(); |
| 209 | inner.apply_dhcp_config(&mut dhcp_socket, config); | 290 | inner.apply_dhcp_config(&mut dhcp_socket, config); |
| 210 | let handle = socket.sockets.add(dhcp_socket); | 291 | let handle = socket.sockets.add(dhcp_socket); |
| 211 | inner.dhcp_socket = Some(handle); | 292 | inner.dhcp_socket = Some(handle); |
| 212 | } | 293 | } |
| 294 | ConfigV4::None => {} | ||
| 295 | } | ||
| 296 | #[cfg(feature = "proto-ipv6")] | ||
| 297 | match config.ipv6 { | ||
| 298 | ConfigV6::Static(config) => { | ||
| 299 | inner.apply_config_v6(&mut socket, config); | ||
| 300 | } | ||
| 301 | ConfigV6::None => {} | ||
| 213 | } | 302 | } |
| 214 | 303 | ||
| 215 | Self { | 304 | Self { |
| @@ -239,12 +328,40 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 239 | /// Get whether the network stack has a valid IP configuration. | 328 | /// Get whether the network stack has a valid IP configuration. |
| 240 | /// This is true if the network stack has a static IP configuration or if DHCP has completed | 329 | /// This is true if the network stack has a static IP configuration or if DHCP has completed |
| 241 | pub fn is_config_up(&self) -> bool { | 330 | pub fn is_config_up(&self) -> bool { |
| 242 | self.with(|_s, i| i.config.is_some()) | 331 | let v4_up; |
| 332 | let v6_up; | ||
| 333 | |||
| 334 | #[cfg(feature = "proto-ipv4")] | ||
| 335 | { | ||
| 336 | v4_up = self.config_v4().is_some(); | ||
| 337 | } | ||
| 338 | #[cfg(not(feature = "proto-ipv4"))] | ||
| 339 | { | ||
| 340 | v4_up = false; | ||
| 341 | } | ||
| 342 | |||
| 343 | #[cfg(feature = "proto-ipv6")] | ||
| 344 | { | ||
| 345 | v6_up = self.config_v6().is_some(); | ||
| 346 | } | ||
| 347 | #[cfg(not(feature = "proto-ipv6"))] | ||
| 348 | { | ||
| 349 | v6_up = false; | ||
| 350 | } | ||
| 351 | |||
| 352 | v4_up || v6_up | ||
| 243 | } | 353 | } |
| 244 | 354 | ||
| 245 | /// Get the current IP configuration. | 355 | /// Get the current IPv4 configuration. |
| 246 | pub fn config(&self) -> Option<StaticConfig> { | 356 | #[cfg(feature = "proto-ipv4")] |
| 247 | self.with(|_s, i| i.config.clone()) | 357 | pub fn config_v4(&self) -> Option<StaticConfigV4> { |
| 358 | self.with(|_s, i| i.static_v4.clone()) | ||
| 359 | } | ||
| 360 | |||
| 361 | /// Get the current IPv6 configuration. | ||
| 362 | #[cfg(feature = "proto-ipv6")] | ||
| 363 | pub fn config_v6(&self) -> Option<StaticConfigV6> { | ||
| 364 | self.with(|_s, i| i.static_v6.clone()) | ||
| 248 | } | 365 | } |
| 249 | 366 | ||
| 250 | /// Run the network stack. | 367 | /// Run the network stack. |
| @@ -264,6 +381,7 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 264 | pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> { | 381 | pub async fn dns_query(&self, name: &str, qtype: dns::DnsQueryType) -> Result<Vec<IpAddress, 1>, dns::Error> { |
| 265 | // For A and AAAA queries we try detect whether `name` is just an IP address | 382 | // For A and AAAA queries we try detect whether `name` is just an IP address |
| 266 | match qtype { | 383 | match qtype { |
| 384 | #[cfg(feature = "proto-ipv4")] | ||
| 267 | dns::DnsQueryType::A => { | 385 | dns::DnsQueryType::A => { |
| 268 | if let Ok(ip) = name.parse().map(IpAddress::Ipv4) { | 386 | if let Ok(ip) = name.parse().map(IpAddress::Ipv4) { |
| 269 | return Ok([ip].into_iter().collect()); | 387 | return Ok([ip].into_iter().collect()); |
| @@ -374,7 +492,8 @@ impl SocketStack { | |||
| 374 | } | 492 | } |
| 375 | 493 | ||
| 376 | impl<D: Driver + 'static> Inner<D> { | 494 | impl<D: Driver + 'static> Inner<D> { |
| 377 | fn apply_config(&mut self, s: &mut SocketStack, config: StaticConfig) { | 495 | #[cfg(feature = "proto-ipv4")] |
| 496 | fn apply_config_v4(&mut self, s: &mut SocketStack, config: StaticConfigV4) { | ||
| 378 | #[cfg(feature = "medium-ethernet")] | 497 | #[cfg(feature = "medium-ethernet")] |
| 379 | let medium = self.device.capabilities().medium; | 498 | let medium = self.device.capabilities().medium; |
| 380 | 499 | ||
| @@ -403,14 +522,86 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 403 | debug!(" DNS server {}: {}", i, s); | 522 | debug!(" DNS server {}: {}", i, s); |
| 404 | } | 523 | } |
| 405 | 524 | ||
| 525 | self.static_v4 = Some(config); | ||
| 526 | |||
| 406 | #[cfg(feature = "dns")] | 527 | #[cfg(feature = "dns")] |
| 407 | { | 528 | { |
| 408 | let socket = s.sockets.get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket); | 529 | self.update_dns_servers(s) |
| 409 | let servers: Vec<IpAddress, 3> = config.dns_servers.iter().map(|c| IpAddress::Ipv4(*c)).collect(); | 530 | } |
| 410 | socket.update_servers(&servers[..]); | 531 | } |
| 532 | |||
| 533 | /// Replaces the current IPv6 static configuration with a newly supplied config. | ||
| 534 | #[cfg(feature = "proto-ipv6")] | ||
| 535 | fn apply_config_v6(&mut self, s: &mut SocketStack, config: StaticConfigV6) { | ||
| 536 | #[cfg(feature = "medium-ethernet")] | ||
| 537 | let medium = self.device.capabilities().medium; | ||
| 538 | |||
| 539 | debug!("Acquired IPv6 configuration:"); | ||
| 540 | |||
| 541 | debug!(" IP address: {}", config.address); | ||
| 542 | s.iface.update_ip_addrs(|addrs| { | ||
| 543 | if addrs.is_empty() { | ||
| 544 | addrs.push(IpCidr::Ipv6(config.address)).unwrap(); | ||
| 545 | } else { | ||
| 546 | addrs[0] = IpCidr::Ipv6(config.address); | ||
| 547 | } | ||
| 548 | }); | ||
| 549 | |||
| 550 | #[cfg(feature = "medium-ethernet")] | ||
| 551 | if Medium::Ethernet == medium { | ||
| 552 | if let Some(gateway) = config.gateway { | ||
| 553 | debug!(" Default gateway: {}", gateway); | ||
| 554 | s.iface.routes_mut().add_default_ipv6_route(gateway).unwrap(); | ||
| 555 | } else { | ||
| 556 | debug!(" Default gateway: None"); | ||
| 557 | s.iface.routes_mut().remove_default_ipv6_route(); | ||
| 558 | } | ||
| 559 | } | ||
| 560 | for (i, s) in config.dns_servers.iter().enumerate() { | ||
| 561 | debug!(" DNS server {}: {}", i, s); | ||
| 411 | } | 562 | } |
| 412 | 563 | ||
| 413 | self.config = Some(config) | 564 | self.static_v6 = Some(config); |
| 565 | |||
| 566 | #[cfg(feature = "dns")] | ||
| 567 | { | ||
| 568 | self.update_dns_servers(s) | ||
| 569 | } | ||
| 570 | } | ||
| 571 | |||
| 572 | #[cfg(feature = "dns")] | ||
| 573 | fn update_dns_servers(&mut self, s: &mut SocketStack) { | ||
| 574 | let socket = s.sockets.get_mut::<smoltcp::socket::dns::Socket>(self.dns_socket); | ||
| 575 | |||
| 576 | let servers_v4; | ||
| 577 | #[cfg(feature = "proto-ipv4")] | ||
| 578 | { | ||
| 579 | servers_v4 = self | ||
| 580 | .static_v4 | ||
| 581 | .iter() | ||
| 582 | .flat_map(|cfg| cfg.dns_servers.iter().map(|c| IpAddress::Ipv4(*c))); | ||
| 583 | }; | ||
| 584 | #[cfg(not(feature = "proto-ipv4"))] | ||
| 585 | { | ||
| 586 | servers_v4 = core::iter::empty(); | ||
| 587 | } | ||
| 588 | |||
| 589 | let servers_v6; | ||
| 590 | #[cfg(feature = "proto-ipv6")] | ||
| 591 | { | ||
| 592 | servers_v6 = self | ||
| 593 | .static_v6 | ||
| 594 | .iter() | ||
| 595 | .flat_map(|cfg| cfg.dns_servers.iter().map(|c| IpAddress::Ipv6(*c))); | ||
| 596 | } | ||
| 597 | #[cfg(not(feature = "proto-ipv6"))] | ||
| 598 | { | ||
| 599 | servers_v6 = core::iter::empty(); | ||
| 600 | } | ||
| 601 | |||
| 602 | // Prefer the v6 DNS servers over the v4 servers | ||
| 603 | let servers: Vec<IpAddress, 6> = servers_v6.chain(servers_v4).collect(); | ||
| 604 | socket.update_servers(&servers[..]); | ||
| 414 | } | 605 | } |
| 415 | 606 | ||
| 416 | #[cfg(feature = "dhcpv4")] | 607 | #[cfg(feature = "dhcpv4")] |
| @@ -430,9 +621,15 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 430 | s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear()); | 621 | s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear()); |
| 431 | #[cfg(feature = "medium-ethernet")] | 622 | #[cfg(feature = "medium-ethernet")] |
| 432 | if medium == Medium::Ethernet { | 623 | if medium == Medium::Ethernet { |
| 433 | s.iface.routes_mut().remove_default_ipv4_route(); | 624 | #[cfg(feature = "proto-ipv4")] |
| 625 | { | ||
| 626 | s.iface.routes_mut().remove_default_ipv4_route(); | ||
| 627 | } | ||
| 628 | } | ||
| 629 | #[cfg(feature = "proto-ipv4")] | ||
| 630 | { | ||
| 631 | self.static_v4 = None | ||
| 434 | } | 632 | } |
| 435 | self.config = None | ||
| 436 | } | 633 | } |
| 437 | 634 | ||
| 438 | fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) { | 635 | fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) { |
| @@ -470,12 +667,12 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 470 | None => {} | 667 | None => {} |
| 471 | Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s), | 668 | Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s), |
| 472 | Some(dhcpv4::Event::Configured(config)) => { | 669 | Some(dhcpv4::Event::Configured(config)) => { |
| 473 | let config = StaticConfig { | 670 | let config = StaticConfigV4 { |
| 474 | address: config.address, | 671 | address: config.address, |
| 475 | gateway: config.router, | 672 | gateway: config.router, |
| 476 | dns_servers: config.dns_servers, | 673 | dns_servers: config.dns_servers, |
| 477 | }; | 674 | }; |
| 478 | self.apply_config(s, config) | 675 | self.apply_config_v4(s, config) |
| 479 | } | 676 | } |
| 480 | } | 677 | } |
| 481 | } else if old_link_up { | 678 | } else if old_link_up { |
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 515bbc5be..367675b13 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs | |||
| @@ -480,7 +480,10 @@ pub mod client { | |||
| 480 | Self: 'a, | 480 | Self: 'a, |
| 481 | { | 481 | { |
| 482 | let addr: crate::IpAddress = match remote.ip() { | 482 | let addr: crate::IpAddress = match remote.ip() { |
| 483 | #[cfg(feature = "proto-ipv4")] | ||
| 483 | IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())), | 484 | IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())), |
| 485 | #[cfg(not(feature = "proto-ipv4"))] | ||
| 486 | IpAddr::V4(_) => panic!("ipv4 support not enabled"), | ||
| 484 | #[cfg(feature = "proto-ipv6")] | 487 | #[cfg(feature = "proto-ipv6")] |
| 485 | IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())), | 488 | IpAddr::V6(addr) => crate::IpAddress::Ipv6(crate::Ipv6Address::from_bytes(&addr.octets())), |
| 486 | #[cfg(not(feature = "proto-ipv6"))] | 489 | #[cfg(not(feature = "proto-ipv6"))] |
diff --git a/examples/nrf52840/src/bin/usb_ethernet.rs b/examples/nrf52840/src/bin/usb_ethernet.rs index 1065f5b5d..f527c0d7f 100644 --- a/examples/nrf52840/src/bin/usb_ethernet.rs +++ b/examples/nrf52840/src/bin/usb_ethernet.rs | |||
| @@ -97,12 +97,12 @@ async fn main(spawner: Spawner) { | |||
| 97 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 97 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 98 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 98 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 99 | 99 | ||
| 100 | let config = embassy_net::Config::Dhcp(Default::default()); | 100 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 101 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 101 | // let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 102 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 102 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 103 | // dns_servers: Vec::new(), | 103 | // dns_servers: Vec::new(), |
| 104 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 104 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
| 105 | //}); | 105 | // }); |
| 106 | 106 | ||
| 107 | // Generate random seed | 107 | // Generate random seed |
| 108 | let mut rng = Rng::new(p.RNG, Irqs); | 108 | let mut rng = Rng::new(p.RNG, Irqs); |
diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index 63e142e7d..82568254a 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs | |||
| @@ -64,7 +64,7 @@ async fn main(spawner: Spawner) { | |||
| 64 | // Init network stack | 64 | // Init network stack |
| 65 | let stack = &*make_static!(Stack::new( | 65 | let stack = &*make_static!(Stack::new( |
| 66 | device, | 66 | device, |
| 67 | embassy_net::Config::Dhcp(Default::default()), | 67 | embassy_net::Config::dhcpv4(Default::default()), |
| 68 | make_static!(StackResources::<3>::new()), | 68 | make_static!(StackResources::<3>::new()), |
| 69 | seed | 69 | seed |
| 70 | )); | 70 | )); |
| @@ -120,9 +120,9 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16) | |||
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 123 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 124 | loop { | 124 | loop { |
| 125 | if let Some(config) = stack.config() { | 125 | if let Some(config) = stack.config_v4() { |
| 126 | return config.clone(); | 126 | return config.clone(); |
| 127 | } | 127 | } |
| 128 | yield_now().await; | 128 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs index a532de00d..d562defad 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_client.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_client.rs | |||
| @@ -67,7 +67,7 @@ async fn main(spawner: Spawner) { | |||
| 67 | // Init network stack | 67 | // Init network stack |
| 68 | let stack = &*make_static!(Stack::new( | 68 | let stack = &*make_static!(Stack::new( |
| 69 | device, | 69 | device, |
| 70 | embassy_net::Config::Dhcp(Default::default()), | 70 | embassy_net::Config::dhcpv4(Default::default()), |
| 71 | make_static!(StackResources::<2>::new()), | 71 | make_static!(StackResources::<2>::new()), |
| 72 | seed | 72 | seed |
| 73 | )); | 73 | )); |
| @@ -108,9 +108,9 @@ async fn main(spawner: Spawner) { | |||
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 111 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 112 | loop { | 112 | loop { |
| 113 | if let Some(config) = stack.config() { | 113 | if let Some(config) = stack.config_v4() { |
| 114 | return config.clone(); | 114 | return config.clone(); |
| 115 | } | 115 | } |
| 116 | yield_now().await; | 116 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs index 599f6b1e9..7f521cdb4 100644 --- a/examples/rp/src/bin/ethernet_w5500_tcp_server.rs +++ b/examples/rp/src/bin/ethernet_w5500_tcp_server.rs | |||
| @@ -65,7 +65,7 @@ async fn main(spawner: Spawner) { | |||
| 65 | // Init network stack | 65 | // Init network stack |
| 66 | let stack = &*make_static!(Stack::new( | 66 | let stack = &*make_static!(Stack::new( |
| 67 | device, | 67 | device, |
| 68 | embassy_net::Config::Dhcp(Default::default()), | 68 | embassy_net::Config::dhcpv4(Default::default()), |
| 69 | make_static!(StackResources::<2>::new()), | 69 | make_static!(StackResources::<2>::new()), |
| 70 | seed | 70 | seed |
| 71 | )); | 71 | )); |
| @@ -116,9 +116,9 @@ async fn main(spawner: Spawner) { | |||
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 119 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 120 | loop { | 120 | loop { |
| 121 | if let Some(config) = stack.config() { | 121 | if let Some(config) = stack.config_v4() { |
| 122 | return config.clone(); | 122 | return config.clone(); |
| 123 | } | 123 | } |
| 124 | yield_now().await; | 124 | yield_now().await; |
diff --git a/examples/rp/src/bin/ethernet_w5500_udp.rs b/examples/rp/src/bin/ethernet_w5500_udp.rs index ac5a65bb6..ada86ae55 100644 --- a/examples/rp/src/bin/ethernet_w5500_udp.rs +++ b/examples/rp/src/bin/ethernet_w5500_udp.rs | |||
| @@ -62,7 +62,7 @@ async fn main(spawner: Spawner) { | |||
| 62 | // Init network stack | 62 | // Init network stack |
| 63 | let stack = &*make_static!(Stack::new( | 63 | let stack = &*make_static!(Stack::new( |
| 64 | device, | 64 | device, |
| 65 | embassy_net::Config::Dhcp(Default::default()), | 65 | embassy_net::Config::dhcpv4(Default::default()), |
| 66 | make_static!(StackResources::<2>::new()), | 66 | make_static!(StackResources::<2>::new()), |
| 67 | seed | 67 | seed |
| 68 | )); | 68 | )); |
| @@ -95,9 +95,9 @@ async fn main(spawner: Spawner) { | |||
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfig { | 98 | async fn wait_for_config(stack: &'static Stack<Device<'static>>) -> embassy_net::StaticConfigV4 { |
| 99 | loop { | 99 | loop { |
| 100 | if let Some(config) = stack.config() { | 100 | if let Some(config) = stack.config_v4() { |
| 101 | return config.clone(); | 101 | return config.clone(); |
| 102 | } | 102 | } |
| 103 | yield_now().await; | 103 | yield_now().await; |
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index 16fbf5e91..91d1ec8e7 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs | |||
| @@ -86,8 +86,8 @@ async fn main(spawner: Spawner) { | |||
| 86 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 86 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 87 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 87 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 88 | 88 | ||
| 89 | let config = embassy_net::Config::Dhcp(Default::default()); | 89 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 90 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 90 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 91 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 91 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 92 | // dns_servers: Vec::new(), | 92 | // dns_servers: Vec::new(), |
| 93 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 93 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/rp/src/bin/wifi_ap_tcp_server.rs b/examples/rp/src/bin/wifi_ap_tcp_server.rs index b27d3c9f8..e8197390c 100644 --- a/examples/rp/src/bin/wifi_ap_tcp_server.rs +++ b/examples/rp/src/bin/wifi_ap_tcp_server.rs | |||
| @@ -62,7 +62,7 @@ async fn main(spawner: Spawner) { | |||
| 62 | .await; | 62 | .await; |
| 63 | 63 | ||
| 64 | // Use a link-local address for communication without DHCP server | 64 | // Use a link-local address for communication without DHCP server |
| 65 | let config = Config::Static(embassy_net::StaticConfig { | 65 | let config = Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 66 | address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16), | 66 | address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(169, 254, 1, 1), 16), |
| 67 | dns_servers: heapless::Vec::new(), | 67 | dns_servers: heapless::Vec::new(), |
| 68 | gateway: None, | 68 | gateway: None, |
diff --git a/examples/rp/src/bin/wifi_tcp_server.rs b/examples/rp/src/bin/wifi_tcp_server.rs index 1a00bca96..026e056fa 100644 --- a/examples/rp/src/bin/wifi_tcp_server.rs +++ b/examples/rp/src/bin/wifi_tcp_server.rs | |||
| @@ -61,8 +61,8 @@ async fn main(spawner: Spawner) { | |||
| 61 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | 61 | .set_power_management(cyw43::PowerManagementMode::PowerSave) |
| 62 | .await; | 62 | .await; |
| 63 | 63 | ||
| 64 | let config = Config::Dhcp(Default::default()); | 64 | let config = Config::dhcpv4(Default::default()); |
| 65 | //let config = embassy_net::Config::Static(embassy_net::Config { | 65 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 66 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 66 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 67 | // dns_servers: Vec::new(), | 67 | // dns_servers: Vec::new(), |
| 68 | // gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 68 | // gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index b42bfc13b..3aadb029d 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs | |||
| @@ -42,13 +42,13 @@ async fn main_task(spawner: Spawner) { | |||
| 42 | 42 | ||
| 43 | // Choose between dhcp or static ip | 43 | // Choose between dhcp or static ip |
| 44 | let config = if opts.static_ip { | 44 | let config = if opts.static_ip { |
| 45 | Config::Static(embassy_net::StaticConfig { | 45 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 46 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 46 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 47 | dns_servers: Vec::new(), | 47 | dns_servers: Vec::new(), |
| 48 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 48 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 49 | }) | 49 | }) |
| 50 | } else { | 50 | } else { |
| 51 | Config::Dhcp(Default::default()) | 51 | Config::dhcpv4(Default::default()) |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | // Generate random seed | 54 | // Generate random seed |
diff --git a/examples/std/src/bin/net_dns.rs b/examples/std/src/bin/net_dns.rs index 932ac5831..65b5a2cd9 100644 --- a/examples/std/src/bin/net_dns.rs +++ b/examples/std/src/bin/net_dns.rs | |||
| @@ -40,14 +40,14 @@ async fn main_task(spawner: Spawner) { | |||
| 40 | 40 | ||
| 41 | // Choose between dhcp or static ip | 41 | // Choose between dhcp or static ip |
| 42 | let config = if opts.static_ip { | 42 | let config = if opts.static_ip { |
| 43 | Config::Static(embassy_net::StaticConfig { | 43 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 44 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), | 44 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 1), 24), |
| 45 | dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) | 45 | dns_servers: Vec::from_slice(&[Ipv4Address::new(8, 8, 4, 4).into(), Ipv4Address::new(8, 8, 8, 8).into()]) |
| 46 | .unwrap(), | 46 | .unwrap(), |
| 47 | gateway: Some(Ipv4Address::new(192, 168, 69, 100)), | 47 | gateway: Some(Ipv4Address::new(192, 168, 69, 100)), |
| 48 | }) | 48 | }) |
| 49 | } else { | 49 | } else { |
| 50 | Config::Dhcp(Default::default()) | 50 | Config::dhcpv4(Default::default()) |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | // Generate random seed | 53 | // Generate random seed |
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs index d89ec7643..3fc46156c 100644 --- a/examples/std/src/bin/net_udp.rs +++ b/examples/std/src/bin/net_udp.rs | |||
| @@ -38,13 +38,13 @@ async fn main_task(spawner: Spawner) { | |||
| 38 | 38 | ||
| 39 | // Choose between dhcp or static ip | 39 | // Choose between dhcp or static ip |
| 40 | let config = if opts.static_ip { | 40 | let config = if opts.static_ip { |
| 41 | Config::Static(embassy_net::StaticConfig { | 41 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 42 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 42 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 43 | dns_servers: Vec::new(), | 43 | dns_servers: Vec::new(), |
| 44 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 44 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 45 | }) | 45 | }) |
| 46 | } else { | 46 | } else { |
| 47 | Config::Dhcp(Default::default()) | 47 | Config::dhcpv4(Default::default()) |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | // Generate random seed | 50 | // Generate random seed |
diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index 01695baea..df09986ac 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs | |||
| @@ -53,13 +53,13 @@ async fn main_task(spawner: Spawner) { | |||
| 53 | 53 | ||
| 54 | // Choose between dhcp or static ip | 54 | // Choose between dhcp or static ip |
| 55 | let config = if opts.static_ip { | 55 | let config = if opts.static_ip { |
| 56 | Config::Static(embassy_net::StaticConfig { | 56 | Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 57 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 57 | address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 58 | dns_servers: Vec::new(), | 58 | dns_servers: Vec::new(), |
| 59 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), | 59 | gateway: Some(Ipv4Address::new(192, 168, 69, 1)), |
| 60 | }) | 60 | }) |
| 61 | } else { | 61 | } else { |
| 62 | Config::Dhcp(Default::default()) | 62 | Config::dhcpv4(Default::default()) |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | // Generate random seed | 65 | // Generate random seed |
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs index d229cc3ef..953d99a45 100644 --- a/examples/stm32f4/src/bin/usb_ethernet.rs +++ b/examples/stm32f4/src/bin/usb_ethernet.rs | |||
| @@ -94,8 +94,8 @@ async fn main(spawner: Spawner) { | |||
| 94 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 94 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 95 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 95 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 96 | 96 | ||
| 97 | let config = embassy_net::Config::Dhcp(Default::default()); | 97 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 98 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 98 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 99 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 99 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 100 | // dns_servers: Vec::new(), | 100 | // dns_servers: Vec::new(), |
| 101 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 101 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index d8438241c..fde6a7576 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -62,8 +62,8 @@ async fn main(spawner: Spawner) -> ! { | |||
| 62 | 0, | 62 | 0, |
| 63 | ); | 63 | ); |
| 64 | 64 | ||
| 65 | let config = embassy_net::Config::Dhcp(Default::default()); | 65 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 66 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 66 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 67 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 67 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 68 | // dns_servers: Vec::new(), | 68 | // dns_servers: Vec::new(), |
| 69 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 69 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index 5d1eadf4b..78c8282a6 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs | |||
| @@ -81,8 +81,8 @@ async fn main(spawner: Spawner) -> ! { | |||
| 81 | 0, | 81 | 0, |
| 82 | ); | 82 | ); |
| 83 | 83 | ||
| 84 | let config = embassy_net::Config::Dhcp(Default::default()); | 84 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 85 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 85 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 86 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 86 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 87 | // dns_servers: Vec::new(), | 87 | // dns_servers: Vec::new(), |
| 88 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 88 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 3aa7b2271..12d37f7a4 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -63,8 +63,8 @@ async fn main(spawner: Spawner) -> ! { | |||
| 63 | 0, | 63 | 0, |
| 64 | ); | 64 | ); |
| 65 | 65 | ||
| 66 | let config = embassy_net::Config::Dhcp(Default::default()); | 66 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 67 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 67 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 68 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 68 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 69 | // dns_servers: Vec::new(), | 69 | // dns_servers: Vec::new(), |
| 70 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 70 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 575c716b6..6078fc3fe 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -64,8 +64,8 @@ async fn main(spawner: Spawner) -> ! { | |||
| 64 | 0, | 64 | 0, |
| 65 | ); | 65 | ); |
| 66 | 66 | ||
| 67 | let config = embassy_net::Config::Dhcp(Default::default()); | 67 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 68 | //let config = embassy_net::Config::StaticConfig(embassy_net::Config { | 68 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 69 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 69 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 70 | // dns_servers: Vec::new(), | 70 | // dns_servers: Vec::new(), |
| 71 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 71 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 6163e0709..32eba4277 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -91,8 +91,8 @@ async fn main(spawner: Spawner) { | |||
| 91 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 91 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); |
| 92 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 92 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 93 | 93 | ||
| 94 | let config = embassy_net::Config::Dhcp(Default::default()); | 94 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| 95 | //let config = embassy_net::Config::Static(embassy_net::StaticConfig { | 95 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { |
| 96 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | 96 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), |
| 97 | // dns_servers: Vec::new(), | 97 | // dns_servers: Vec::new(), |
| 98 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | 98 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), |
diff --git a/tests/rp/src/bin/cyw43-perf.rs b/tests/rp/src/bin/cyw43-perf.rs index 568f1b826..7a94ea191 100644 --- a/tests/rp/src/bin/cyw43-perf.rs +++ b/tests/rp/src/bin/cyw43-perf.rs | |||
| @@ -63,7 +63,7 @@ async fn main(spawner: Spawner) { | |||
| 63 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | 63 | .set_power_management(cyw43::PowerManagementMode::PowerSave) |
| 64 | .await; | 64 | .await; |
| 65 | 65 | ||
| 66 | let config = Config::Dhcp(Default::default()); | 66 | let config = Config::dhcpv4(Default::default()); |
| 67 | //let config = embassy_net::Config::Static(embassy_net::Config { | 67 | //let config = embassy_net::Config::Static(embassy_net::Config { |
| 68 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 68 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| 69 | // dns_servers: Vec::new(), | 69 | // dns_servers: Vec::new(), |
| @@ -93,7 +93,7 @@ async fn main(spawner: Spawner) { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | info!("Waiting for DHCP up..."); | 95 | info!("Waiting for DHCP up..."); |
| 96 | while stack.config().is_none() { | 96 | while stack.config_v4().is_none() { |
| 97 | Timer::after(Duration::from_millis(100)).await; | 97 | Timer::after(Duration::from_millis(100)).await; |
| 98 | } | 98 | } |
| 99 | info!("IP addressing up!"); | 99 | info!("IP addressing up!"); |
| @@ -115,9 +115,9 @@ const WIFI_NETWORK: &str = "EmbassyTest"; | |||
| 115 | const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud"; | 115 | const WIFI_PASSWORD: &str = "V8YxhKt5CdIAJFud"; |
| 116 | 116 | ||
| 117 | const TEST_DURATION: usize = 10; | 117 | const TEST_DURATION: usize = 10; |
| 118 | const TEST_EXPECTED_DOWNLOAD_KBPS: usize = 500; | 118 | const TEST_EXPECTED_DOWNLOAD_KBPS: usize = 300; |
| 119 | const TEST_EXPECTED_UPLOAD_KBPS: usize = 500; | 119 | const TEST_EXPECTED_UPLOAD_KBPS: usize = 300; |
| 120 | const TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS: usize = 400; | 120 | const TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS: usize = 300; |
| 121 | const RX_BUFFER_SIZE: usize = 4096; | 121 | const RX_BUFFER_SIZE: usize = 4096; |
| 122 | const TX_BUFFER_SIZE: usize = 4096; | 122 | const TX_BUFFER_SIZE: usize = 4096; |
| 123 | const SERVER_ADDRESS: Ipv4Address = Ipv4Address::new(192, 168, 2, 2); | 123 | const SERVER_ADDRESS: Ipv4Address = Ipv4Address::new(192, 168, 2, 2); |
