Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no_std + async support #72

Merged
merged 72 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
40f353c
Support for no_std
ivmarkov Feb 2, 2023
817d55a
Start reintroducing long reads and subscriptions from mainline
ivmarkov Apr 21, 2023
fcc87bf
Long reads and subscriptions reintroduced
ivmarkov Apr 22, 2023
89aab6f
Remove allocations from Base38 and QR calc
ivmarkov Apr 23, 2023
bcbac96
Remove allocations from Cert handling
ivmarkov Apr 24, 2023
b4b549b
Fix several no_std incompatibilities
ivmarkov Apr 24, 2023
bd87ac4
Linux & MacOS mDNS services now implement the Mdns trait
ivmarkov Apr 24, 2023
d9c99d7
Chrono dep made optional
ivmarkov Apr 24, 2023
505fa39
Create new secure channel sessions without async-channel
ivmarkov Apr 24, 2023
688d7ea
More ergonomic api when STD is available
ivmarkov Apr 24, 2023
d934912
Fix compilation error since the introduction of UtcCalendar
ivmarkov Apr 24, 2023
d558c73
Cleanup the dependencies as much as possible
ivmarkov Apr 24, 2023
faf5af3
no_std printing of QR code (kind of...)
ivmarkov Apr 24, 2023
2ea3143
On-off example now buildable
ivmarkov Apr 24, 2023
eb3c9cd
Cleanup a bit the mDns story
ivmarkov Apr 24, 2023
36011c2
Actually add the bonjour feature
ivmarkov Apr 24, 2023
8b3bb95
Comm with chip-tool
ivmarkov Apr 24, 2023
7ef7e93
Heap-allocated packets not necessary; no_std and no-alloc build suppo…
ivmarkov Apr 25, 2023
9a23a2a
Bugfix: arm failsafe was reporting wrong status
ivmarkov Apr 25, 2023
b280557
Restore transaction completion code
ivmarkov Apr 25, 2023
f9536be
Bugfix: two separate failsafe instances were used
ivmarkov Apr 25, 2023
f804c21
Bugfix: fabric adding wrongly started at index 0
ivmarkov Apr 26, 2023
9964466
MRP standalone ack messages should not be acknowledged
ivmarkov Apr 26, 2023
2fc4e6d
Root cert buffer too short
ivmarkov Apr 26, 2023
09a523f
TX packets are reused; need way to reset them
ivmarkov Apr 28, 2023
2a57ecb
Bugfix: only report devtype for the queried endpoint
ivmarkov Apr 28, 2023
635be2c
Error log on arm failure
ivmarkov Apr 28, 2023
076ba06
Bugfix: missing descriptor cluster
ivmarkov Apr 28, 2023
e8e847c
Bugfix: subscription_id was not sent
ivmarkov Apr 28, 2023
4b39884
Bugfix: unnecessary struct container
ivmarkov Apr 28, 2023
86e01a0
Simple persistance via TLV
ivmarkov Apr 29, 2023
934ecb9
Persistence bugfixing
ivmarkov Apr 29, 2023
3dccc0d
Persistence - trace info
ivmarkov Apr 29, 2023
974ac4d
Optional feature to capture stacktrace on error
Apr 29, 2023
89014ed
Remove heapless::String from QR API
ivmarkov Apr 29, 2023
06b0fcd
Fix no_std errors
ivmarkov May 4, 2023
695869f
Fix compilation errors in crypto
ivmarkov May 4, 2023
e741cab
More crypto fixes
ivmarkov May 4, 2023
9d59c79
Colorizing is now no_std compatible
ivmarkov May 4, 2023
a4b8b53
Builds for STD with ESP IDF
ivmarkov May 4, 2023
592d1ee
Just use time-rs in no_std mode
ivmarkov May 4, 2023
870ae6f
Move MATTER_PORT outside of STD-only udp module
ivmarkov May 4, 2023
bd61c95
no_std needs default features switched off for several crates
ivmarkov May 5, 2023
1e6cd69
built-in mDNS; memory optimizations
ivmarkov May 24, 2023
357eb73
Control memory by removing implicit copy
ivmarkov May 28, 2023
931e306
Clippy
ivmarkov May 28, 2023
443324a
More inlines
ivmarkov May 28, 2023
2cde378
Make the example working again
ivmarkov May 28, 2023
b94484b
Make sure nix is not brought in no-std compiles
ivmarkov May 31, 2023
8e9d888
Fix a bug in mDNS
ivmarkov Jun 1, 2023
1b879f1
Simplify main user-facing API
ivmarkov Jun 9, 2023
de3d3de
Make Matter covariant over its lifetime
ivmarkov Jun 10, 2023
c0d1b85
Default mDns impl
ivmarkov Jun 10, 2023
b882aad
Clippy
ivmarkov Jun 10, 2023
488ef5b
Proper mDNS responder
ivmarkov Jun 12, 2023
e8babed
Support for ESP-IDF build
ivmarkov Jun 12, 2023
62aa692
Workaround broken join_multicast_v4 on ESP-IDF
ivmarkov Jun 13, 2023
5b9fd50
Fix the no_std build
ivmarkov Jun 13, 2023
879f816
More comments for tailoring the example for no_std
ivmarkov Jun 13, 2023
8318536
Add from/to TLV for i16, i32 and i64
ivmarkov Jun 16, 2023
44e01a5
Configurable parts_list in descriptor
ivmarkov Jun 17, 2023
7f9ccbc
Sequential Exchange API
ivmarkov Jun 10, 2023
9576fd8
Fix #60
ivmarkov Jun 30, 2023
762438c
on_off_light: Save ACLs and Fabrics to PSM
kedars Jul 20, 2023
0eecce5
UDP stack based on embassy-net
ivmarkov Jul 14, 2023
0d73ba7
UDP stack based on embassy-net
ivmarkov Jul 14, 2023
24cdf07
New helper APIs in Transport
ivmarkov Jul 17, 2023
aa2d5df
Compatibility with embassy-net fixed multicast support
ivmarkov Jul 17, 2023
263279e
Make multicast ipv6 optional
ivmarkov Jul 18, 2023
71b9a57
Remove embassy-net features that matter-rs is not using
ivmarkov Jul 19, 2023
916f214
Simplify API by combining Matter, Transport and TransportRunner; simp…
ivmarkov Jul 21, 2023
91e1329
Remove the note referring to the no_std and sequential branches
ivmarkov Jul 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
crypto-backend: ['crypto_openssl', 'crypto_rustcrypto', 'crypto_mbedtls']
crypto-backend: ['rustcrypto', 'mbedtls', 'openssl']

steps:
- uses: actions/checkout@v2
- name: Build
run: cd matter; cargo build --verbose --no-default-features --features ${{matrix.crypto-backend}}
run: cd matter; cargo build --no-default-features --features ${{matrix.crypto-backend}}
- name: Run tests
run: cd matter; cargo test --verbose --no-default-features --features ${{matrix.crypto-backend}} -- --test-threads=1
run: cd matter; cargo test --no-default-features --features os,${{matrix.crypto-backend}} -- --test-threads=1
ivmarkov marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Cargo.lock
.vscode
.embuild
17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[workspace]
members = ["matter", "matter_macro_derive", "boxslab", "tools/tlv_tool"]
resolver = "2"
members = ["matter", "matter_macro_derive"]

exclude = ["examples/*"]
exclude = ["examples/*", "tools/tlv_tool"]

# For compatibility with ESP IDF
[patch.crates-io]
polling = { git = "https://github.com/esp-rs-compat/polling" }
socket2 = { git = "https://github.com/esp-rs-compat/socket2" }

[profile.release]
opt-level = 3

[profile.dev]
debug = true
opt-level = 3
65 changes: 27 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,44 @@
[![Test Linux (OpenSSL)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-openssl.yml)
[![Test Linux (mbedTLS)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml/badge.svg)](https://github.com/project-chip/matter-rs/actions/workflows/test-linux-mbedtls.yml)

## Important Note

All development work is now ongoing in two other branches ([no_std](https://github.com/project-chip/matter-rs/tree/no_std) and [sequential](https://github.com/project-chip/matter-rs/tree/sequential) - explained below). The plan is one of these two branches to become the new `main`.

We highly encourage users to try out both of these branches (there is a working `onoff_light` example in both) and provide feedback.

### [no_std](https://github.com/project-chip/matter-rs/tree/no_std)

The purpose of this branch - as the name suggests - is to introduce `no_std` compatibility to the `matter-rs` library, so that it is possible to target constrained environments like MCUs which more often than not have no support for the Rust Standard library (threads, network sockets, filesystem and so on).

We have been successful in this endeavour. The library now only requires Rust `core` and runs on e.g. ESP32 baremental Rust targets.
When `matter-rs` is used on targets that do not support the Rust Standard Library, user is expected to provide the following:

- A `rand` function that can fill a `&[u8]` slice with random data
- An `epoch` function (a "current time" utility); note that since this utility is only used for measuring timeouts, it is OK to provide a function that e.g. measures elapsed millis since system boot, rather than something that tries to adhere to the UNIX epoch (1/1/1970)
- An MCU-specific UDP stack that the user would need to connect to the `matter-rs` library

Besides just having `no_std` compatibility, the `no_std` branch does not need an allocator. I.e. all structures internal to the `matter-rs` librarty are statically allocated.

Last but not least, the `no_std` branch by itself does **not** do any IO. In other words, it is "compute only" (as in, "give me a network packet and I'll produce one or more that you have to send; how you receive/send those is up to you"). Ditto for persisting fabrics and ACLs - it is up to the user to listen the matter stack for changes to those and persist.

### [sequential](https://github.com/project-chip/matter-rs/tree/sequential)

The `sequential` branch builds on top of the work implemented in the `no_std` branch by utilizing code implemented as `async` functions and methods. Committing to `async` has multiple benefits:

- (Internal for the library) We were able to turn several explicit state machines into implicit ones (after all, `async` is primarily about generating state machines automatically based on "sequential" user codee that uses the async/await language constructs - hence the name of the branch)
- (External, for the user) The ergonomics of the Exchange API in this branch (in other words, the "transport aspect of the Matter CSA spec) is much better, approaching that of dealing with regular TCP/IP sockets in the Rust Standard Library. This is only possible by utilizing async functions and methods, because - let's not forget - `matter-rs` needs to run on MCUs where native threading and task scheduling capabilities might not even exist, hence "sequentially-looking" request/response interaction can only be expressed asynchronously, or with explicit state machines.
- Certain pending concepts are much easier to implement via async functions and methods:
- Re-sending packets which were not acknowledged by the receiver yet (the MRP protocol as per the Matter spec)
- The "initiator" side of an exchange (think client clusters)
- This branch provides facilities to implement asynchronous read, write and invoke handling for server clusters, which is beneficial in certain scenarios (i.e. brdige devices)

The `async` metaphor however comes with a bit higher memory usage, due to not enough optimizations being implemented yet in the rust language when the async code is transpiled to state machines.

## Build

Building the library:
### Building the library

```
$ cargo build
```

Building the example:
### Building and running the example (Linux, MacOS X)

```
$ cargo run --example onoff_light
```

### Building the example (Espressif's ESP-IDF)

* Install all build prerequisites described [here](https://github.com/esp-rs/esp-idf-template#prerequisites)
* Build with the following command line:
```
$ RUST_LOG="matter" cargo run --example onoff_light
export MCU=esp32; export CARGO_TARGET_XTENSA_ESP32_ESPIDF_LINKER=ldproxy; export RUSTFLAGS="-C default-linker-libraries"; export WIFI_SSID=ssid;export WIFI_PASS=pass; cargo build --example onoff_light --no-default-features --features esp-idf --target xtensa-esp32-espidf -Zbuild-std=std,panic_abort
```
* If you are building for a different Espressif MCU, change the `MCU` variable, the `xtensa-esp32-espidf` target and the name of the `CARGO_TARGET_<esp-idf-target-uppercase>_LINKER` variable to match your MCU and its Rust target. Available Espressif MCUs and targets are:
* esp32 / xtensa-esp32-espidf
* esp32s2 / xtensa-esp32s2-espidf
* esp32s3 / xtensa-esp32s3-espidf
* esp32c3 / riscv32imc-esp-espidf
* esp32c5 / riscv32imc-esp-espidf
* esp32c6 / risxcv32imac-esp-espidf
* Put in `WIFI_SSID` / `WIFI_PASS` the SSID & password for your wireless router
* Flash using the `espflash` utility described in the build prerequsites' link above

### Building the example (ESP32-XX baremetal or RP2040)

Coming soon!

## Test

With the chip-tool (the current tool for testing Matter) use the Ethernet commissioning mechanism:
With the `chip-tool` (the current tool for testing Matter) use the Ethernet commissioning mechanism:

```
$ chip-tool pairing code 12344321 <Pairing-Code>
Expand Down
9 changes: 0 additions & 9 deletions boxslab/Cargo.toml

This file was deleted.

237 changes: 0 additions & 237 deletions boxslab/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions examples/onoff_light/src/dev_att.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

use matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher};
use matter::error::Error;
use matter::error::{Error, ErrorCode};

pub struct HardCodedDevAtt {}

Expand Down Expand Up @@ -159,7 +159,7 @@ impl DevAttDataFetcher for HardCodedDevAtt {
data.copy_from_slice(src);
Ok(src.len())
} else {
Err(Error::NoSpace)
Err(ErrorCode::NoSpace.into())
}
}
}
Loading
Loading