Skip to content

Commit

Permalink
treewide: add support for ip_in_core
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Apr 22, 2023
1 parent 6cde685 commit 898a641
Show file tree
Hide file tree
Showing 32 changed files with 283 additions and 142 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ jobs:
if: ${{ matrix.target == 'thumbv7em-none-eabi' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-mqtt --features w5500-tls,p256-cm4
if: ${{ matrix.target == 'thumbv7em-none-eabi' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-ll --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-ll --features ip_in_core,defmt
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-hl --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-dhcp --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-dns --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-mqtt --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}
- run: cargo build --target ${{ matrix.target }} -p w5500-tls --features ip_in_core
if: ${{ matrix.toolchain == 'nightly' }}

test:
name: Test
Expand Down
5 changes: 3 additions & 2 deletions dhcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ categories = ["embedded", "hardware-support", "no-std"]
homepage = "https://github.com/newAM/w5500-rs"

[features]
defmt = ["w5500-hl/defmt", "dep:defmt"]
eh0 = ["w5500-hl/eh0"]
eh1 = ["w5500-hl/eh1"]
defmt = ["w5500-hl/defmt", "dep:defmt"]
ip_in_core = ["w5500-hl/ip_in_core"]
std = ["w5500-hl/std"]

[dependencies]
w5500-hl = { path = "../hl", version = "0.9.0" }
defmt = { version = "0.3", optional = true }
defmt = { version = "0.3.4", optional = true }
log = { version = "0.4", optional = true }

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions dhcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All features are disabled by default.

* `eh0`: Passthrough to [`w5500-hl`].
* `eh1`: Passthrough to [`w5500-hl`].
* `ip_in_core`: Passthrough to [`w5500-hl`].
* `std`: Passthrough to [`w5500-hl`].
* `defmt`: Enable logging with `defmt`. Also a passthrough to [`w5500-hl`].
* `log`: Enable logging with `log`.
Expand Down
1 change: 1 addition & 0 deletions dhcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//!
//! * `eh0`: Passthrough to [`w5500-hl`].
//! * `eh1`: Passthrough to [`w5500-hl`].
//! * `ip_in_core`: Passthrough to [`w5500-hl`].
//! * `std`: Passthrough to [`w5500-hl`].
//! * `defmt`: Enable logging with `defmt`. Also a passthrough to [`w5500-hl`].
//! * `log`: Enable logging with `log`.
Expand Down
10 changes: 5 additions & 5 deletions dhcp/src/pkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,28 +211,28 @@ impl<'a, W: Registers> PktSer<'a, W> {
/// respond to ARP requests.
fn set_ciaddr(&mut self, addr: &Ipv4Addr) -> Result<(), Error<W::Error>> {
self.writer.seek(SeekFrom::Start(12))?;
self.writer.write_all(&addr.octets)
self.writer.write_all(&addr.octets())
}

/// 'your' (client) IP address;
/// filled by server if client doesn't
/// know its own address (ciaddr was 0).
fn set_yiaddr(&mut self, addr: &Ipv4Addr) -> Result<(), Error<W::Error>> {
self.writer.seek(SeekFrom::Start(16))?;
self.writer.write_all(&addr.octets)
self.writer.write_all(&addr.octets())
}

/// Set the IP address of next server to use in bootstrap;
/// returned in DHCPOFFER, DHCPACK by server.
fn set_siaddr(&mut self, addr: &Ipv4Addr) -> Result<(), Error<W::Error>> {
self.writer.seek(SeekFrom::Start(20))?;
self.writer.write_all(&addr.octets)
self.writer.write_all(&addr.octets())
}

/// Relay agent IP address, used in booting via a relay agent.
fn set_giaddr(&mut self, addr: &Ipv4Addr) -> Result<(), Error<W::Error>> {
self.writer.seek(SeekFrom::Start(24))?;
self.writer.write_all(&addr.octets)
self.writer.write_all(&addr.octets())
}

/// Set the hardware address
Expand Down Expand Up @@ -307,7 +307,7 @@ impl<'a, W: Registers> PktSer<'a, W> {

fn set_option_requested_ip(&mut self, ip: &Ipv4Addr) -> Result<(), Error<W::Error>> {
self.writer.write_all(&[Options::RequestedIp.into(), 4])?;
self.writer.write_all(&ip.octets)
self.writer.write_all(&ip.octets())
}

fn set_option_end(&mut self) -> Result<(), Error<W::Error>> {
Expand Down
4 changes: 2 additions & 2 deletions dhcp/tests/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn end_to_end() {
.set_hops(0)
.set_xid(msg.xid())
.set_flags(Flags::default().set_broadcast())
.set_chaddr(&Ipv4Addr::LOCALHOST.octets)
.set_chaddr(&Ipv4Addr::LOCALHOST.octets())
.set_yiaddr(YIADDR)
.opts_mut()
.insert(DhcpOption::MessageType(MessageType::Offer));
Expand All @@ -225,7 +225,7 @@ fn end_to_end() {
.set_hops(0)
.set_xid(msg.xid())
.set_flags(Flags::default().set_broadcast())
.set_chaddr(&Ipv4Addr::LOCALHOST.octets)
.set_chaddr(&Ipv4Addr::LOCALHOST.octets())
.set_yiaddr([1, 2, 3, 4])
.opts_mut()
.insert(DhcpOption::MessageType(MessageType::Ack));
Expand Down
5 changes: 3 additions & 2 deletions dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ categories = ["embedded", "hardware-support", "no-std"]
homepage = "https://github.com/newAM/w5500-rs"

[features]
defmt = ["w5500-hl/defmt", "dep:defmt"]
eh0 = ["w5500-hl/eh0"]
eh1 = ["w5500-hl/eh1"]
defmt = ["w5500-hl/defmt", "dep:defmt"]
ip_in_core = ["w5500-hl/ip_in_core"]
std = ["w5500-hl/std"]

[dependencies]
w5500-hl = { path = "../hl", version = "0.9.0" }
defmt = { version = "0.3", optional = true }
defmt = { version = "0.3.4", optional = true }
log = { version = "0.4", optional = true }

[dev-dependencies]
Expand Down
9 changes: 5 additions & 4 deletions dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ response.done()?;

All features are disabled by default.

* `eh0`: Passthrough to [w5500-hl].
* `eh1`: Passthrough to [w5500-hl].
* `std`: Passthrough to [w5500-hl].
* `eh0`: Passthrough to [`w5500-hl`].
* `eh1`: Passthrough to [`w5500-hl`].
* `ip_in_core`: Passthrough to [`w5500-hl`].
* `std`: Passthrough to [`w5500-hl`].
* `defmt`: Enable logging with `defmt`. Also a passthrough to [w5500-hl].
* `log`: Enable logging with `log`.

[w5500-hl]: https://crates.io/crates/w5500-hl
[`w5500-hl`]: https://crates.io/crates/w5500-hl
[`std::net`]: https://doc.rust-lang.org/std/net/index.html
[Wiznet W5500]: https://www.wiznet.io/product-item/w5500/
9 changes: 5 additions & 4 deletions dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@
//!
//! All features are disabled by default.
//!
//! * `eh0`: Passthrough to [w5500-hl].
//! * `eh1`: Passthrough to [w5500-hl].
//! * `std`: Passthrough to [w5500-hl].
//! * `eh0`: Passthrough to [`w5500-hl`].
//! * `eh1`: Passthrough to [`w5500-hl`].
//! * `ip_in_core`: Passthrough to [`w5500-hl`].
//! * `std`: Passthrough to [`w5500-hl`].
//! * `defmt`: Enable logging with `defmt`. Also a passthrough to [w5500-hl].
//! * `log`: Enable logging with `log`.
//!
//! [w5500-hl]: https://crates.io/crates/w5500-hl
//! [`w5500-hl`]: https://crates.io/crates/w5500-hl
//! [`std::net`]: https://doc.rust-lang.org/std/net/index.html
//! [Wiznet W5500]: https://www.wiznet.io/product-item/w5500/
#![cfg_attr(docsrs, feature(doc_cfg), feature(doc_auto_cfg))]
Expand Down
2 changes: 1 addition & 1 deletion dns/tests/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Registers for MockW5500 {
// reading the UDP header
assert_eq!(buf.len(), UDP_HEADER_LEN);

buf[..4].copy_from_slice(&self.header.origin.ip().octets);
buf[..4].copy_from_slice(&self.header.origin.ip().octets());
buf[4..6].copy_from_slice(&self.header.origin.port().to_be_bytes());
buf[6..8].copy_from_slice(&self.header.len.to_be_bytes());
} else {
Expand Down
3 changes: 2 additions & 1 deletion hl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ homepage = "https://github.com/newAM/w5500-rs"
defmt = ["w5500-ll/defmt", "dep:defmt"]
eh0 = ["w5500-ll/eh0"]
eh1 = ["w5500-ll/eh1"]
ip_in_core = ["w5500-ll/ip_in_core"]
std = ["w5500-ll/std"]

[dependencies]
defmt = { version = "0.3", optional = true }
defmt = { version = "0.3.4", optional = true }
w5500-ll = { path = "../ll", version = "0.10" }

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions hl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All features are disabled by default.
* `defmt`: Passthrough to [`w5500-ll`].
* `eh0`: Passthrough to [`w5500-ll`].
* `eh1`: Passthrough to [`w5500-ll`].
* `ip_in_core`: Passthrough to [`w5500-ll`].
* `std`: Passthrough to [`w5500-ll`].

## Examples
Expand Down
1 change: 1 addition & 0 deletions hl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//! * `defmt`: Passthrough to [`w5500-ll`].
//! * `eh0`: Passthrough to [`w5500-ll`].
//! * `eh1`: Passthrough to [`w5500-ll`].
//! * `ip_in_core`: Passthrough to [`w5500-ll`].
//! * `std`: Passthrough to [`w5500-ll`].
//!
//! # Examples
Expand Down
3 changes: 3 additions & 0 deletions ll/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Added `#[must_use]` to functions in `w5500_ll::net`.
- Added support for `core::net` types with the `ip_in_core` feature.
- Added support for `embedded-hal` version `1.0.0-alpha.10` with the `eh1` feature.
- Added support for `embedded-hal-async` version `0.2.0-alpha.0` with the `eha0a` feature.
- Added an `aio` module with async traits.
Expand All @@ -17,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed the `embedded-hal` version `0.2` feature name to `eh0`.
- Renamed the `blocking` module to `eh0`.
- Moved the `reset` function into the `eh0` and `eh1` modules.
- Replaced public `octets` member on `net::Ipv4Addr` with an `octets()` method.

## [0.10.4] - 2022-07-14
### Added
Expand Down
8 changes: 5 additions & 3 deletions ll/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ categories = ["embedded", "hardware-support", "no-std"]
homepage = "https://github.com/newAM/w5500-rs"

[features]
std = []
async = []
eha0a = ["async", "dep:eha0a", "dep:eh1"]
defmt = ["dep:defmt"]
eh1 = ["dep:eh1"]
eha0a = ["async", "dep:eha0a", "dep:eh1"]
ip_in_core = ["defmt?/ip_in_core"]
std = []

[dependencies]
defmt = { version = "0.3", optional = true }
defmt = { version = "0.3.4", optional = true }
eh0 = { package = "embedded-hal", version = "0.2.7", optional = true }
eh1 = { package = "embedded-hal", version = "=1.0.0-alpha.10", optional = true }
eha0a = { package = "embedded-hal-async", version = "=0.2.0-alpha.1", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions ll/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ All features are disabled by default.
* `eha0a`: **Nightly only.**
Implements the [`aio::Registers`] trait for types in the [`eh1`] module
using the `embedded-hal-async` alpha traits.
* `ip_in_core`: **Nightly only.**
Use `core::net` types for `Ipv4Addr` and `SocketAddrV4`.
* `std`: Enables conversion between [`std::net`] and [`w5500_ll::net`] types.
This is for testing purposes only, the `std` flag will not work on
embedded systems because it uses the standard library.
Expand Down
55 changes: 30 additions & 25 deletions ll/src/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn gar(&mut self) -> Result<Ipv4Addr, Self::Error> {
let mut gar = Ipv4Addr::UNSPECIFIED;
self.read(Reg::GAR0.addr(), COMMON_BLOCK_OFFSET, &mut gar.octets)
let mut gar: [u8; 4] = [0; 4];
self.read(Reg::GAR0.addr(), COMMON_BLOCK_OFFSET, &mut gar)
.await?;
Ok::<Ipv4Addr, Self::Error>(gar)
Ok::<Ipv4Addr, Self::Error>(gar.into())
}

/// Set the gateway IP address.
Expand All @@ -129,7 +129,7 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn set_gar(&mut self, gar: &Ipv4Addr) -> Result<(), Self::Error> {
self.write(Reg::GAR0.addr(), COMMON_BLOCK_OFFSET, &gar.octets)
self.write(Reg::GAR0.addr(), COMMON_BLOCK_OFFSET, &gar.octets())
.await
}

Expand All @@ -154,10 +154,10 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn subr(&mut self) -> Result<Ipv4Addr, Self::Error> {
let mut subr = Ipv4Addr::UNSPECIFIED;
self.read(Reg::SUBR0.addr(), COMMON_BLOCK_OFFSET, &mut subr.octets)
let mut subr: [u8; 4] = [0; 4];
self.read(Reg::SUBR0.addr(), COMMON_BLOCK_OFFSET, &mut subr)
.await?;
Ok::<Ipv4Addr, Self::Error>(subr)
Ok::<Ipv4Addr, Self::Error>(subr.into())
}

/// Set the subnet mask.
Expand All @@ -180,7 +180,7 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn set_subr(&mut self, subr: &Ipv4Addr) -> Result<(), Self::Error> {
self.write(Reg::SUBR0.addr(), COMMON_BLOCK_OFFSET, &subr.octets)
self.write(Reg::SUBR0.addr(), COMMON_BLOCK_OFFSET, &subr.octets())
.await
}

Expand Down Expand Up @@ -258,10 +258,10 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn sipr(&mut self) -> Result<Ipv4Addr, Self::Error> {
let mut sipr = Ipv4Addr::UNSPECIFIED;
self.read(Reg::SIPR0.addr(), COMMON_BLOCK_OFFSET, &mut sipr.octets)
let mut sipr: [u8; 4] = [0; 4];
self.read(Reg::SIPR0.addr(), COMMON_BLOCK_OFFSET, &mut sipr)
.await?;
Ok::<Ipv4Addr, Self::Error>(sipr)
Ok::<Ipv4Addr, Self::Error>(sipr.into())
}

/// Set the source (client) IP address.
Expand All @@ -284,7 +284,7 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn set_sipr(&mut self, sipr: &Ipv4Addr) -> Result<(), Self::Error> {
self.write(Reg::SIPR0.addr(), COMMON_BLOCK_OFFSET, &sipr.octets)
self.write(Reg::SIPR0.addr(), COMMON_BLOCK_OFFSET, &sipr.octets())
.await
}

Expand Down Expand Up @@ -1006,10 +1006,10 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn uipr(&mut self) -> Result<Ipv4Addr, Self::Error> {
let mut uipr = Ipv4Addr::UNSPECIFIED;
self.read(Reg::UIPR0.addr(), COMMON_BLOCK_OFFSET, &mut uipr.octets)
let mut uipr: [u8; 4] = [0; 4];
self.read(Reg::UIPR0.addr(), COMMON_BLOCK_OFFSET, &mut uipr)
.await?;
Ok::<Ipv4Addr, Self::Error>(uipr)
Ok::<Ipv4Addr, Self::Error>(uipr.into())
}

/// Get the unreachable port.
Expand Down Expand Up @@ -1502,10 +1502,10 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn sn_dipr(&mut self, sn: Sn) -> Result<Ipv4Addr, Self::Error> {
let mut dipr: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
self.read(SnReg::DIPR0.addr(), sn.block(), &mut dipr.octets)
let mut dipr: [u8; 4] = [0; 4];
self.read(SnReg::DIPR0.addr(), sn.block(), &mut dipr)
.await?;
Ok::<Ipv4Addr, Self::Error>(dipr)
Ok::<Ipv4Addr, Self::Error>(dipr.into())
}

/// Set the socket destination IP address.
Expand All @@ -1532,7 +1532,7 @@ pub trait Registers {
/// # Ok(()) }
/// ```
async fn set_sn_dipr(&mut self, sn: Sn, dipr: &Ipv4Addr) -> Result<(), Self::Error> {
self.write(SnReg::DIPR0.addr(), sn.block(), &dipr.octets)
self.write(SnReg::DIPR0.addr(), sn.block(), &dipr.octets())
.await
}

Expand Down Expand Up @@ -1618,11 +1618,16 @@ pub trait Registers {
/// # ehm1::spi::Transaction::read_vec(vec![0, 0, 0, 0, 0, 0]),
/// # ehm1::spi::Transaction::transaction_end(),
/// # ]);
/// use w5500_ll::{aio::Registers, eh1::vdm::W5500, net::SocketAddrV4, Sn};
/// use w5500_ll::{
/// aio::Registers,
/// eh1::vdm::W5500,
/// net::{Ipv4Addr, SocketAddrV4},
/// Sn,
/// };
///
/// let mut w5500 = W5500::new(spi);
/// let addr = w5500.sn_dest(Sn::Sn0).await?;
/// assert_eq!(addr, SocketAddrV4::default());
/// assert_eq!(addr, SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), 0));
/// # Ok(()) }
/// ```
async fn sn_dest(&mut self, sn: Sn) -> Result<SocketAddrV4, Self::Error> {
Expand Down Expand Up @@ -1664,10 +1669,10 @@ pub trait Registers {
/// ```
async fn set_sn_dest(&mut self, sn: Sn, addr: &SocketAddrV4) -> Result<(), Self::Error> {
let buf: [u8; 6] = [
addr.ip().octets[0],
addr.ip().octets[1],
addr.ip().octets[2],
addr.ip().octets[3],
addr.ip().octets()[0],
addr.ip().octets()[1],
addr.ip().octets()[2],
addr.ip().octets()[3],
(addr.port() >> 8) as u8,
addr.port() as u8,
];
Expand Down
Loading

0 comments on commit 898a641

Please sign in to comment.