rs_matter/
lib.rs

1/*
2 *
3 *    Copyright (c) 2020-2022 Project CHIP Authors
4 *
5 *    Licensed under the Apache License, Version 2.0 (the "License");
6 *    you may not use this file except in compliance with the License.
7 *    You may obtain a copy of the License at
8 *
9 *        http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *    Unless required by applicable law or agreed to in writing, software
12 *    distributed under the License is distributed on an "AS IS" BASIS,
13 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *    See the License for the specific language governing permissions and
15 *    limitations under the License.
16 */
17
18//! Native Rust Implementation of Matter (Smart-Home)
19//!
20//! This crate implements the Matter specification that can be run on embedded devices
21//! to build Matter-compatible smart-home/IoT devices.
22//!
23//! Currently Ethernet based transport is supported.
24//!
25//! # Examples
26//! TODO: Fix once new API has stabilized a bit
27//! use rs_matter::{Matter, CommissioningData};
28//! use rs_matter::data_model::device_types::device_type_add_on_off_light;
29//! use rs_matter::data_model::cluster_basic_information::BasicInfoConfig;
30//! use rs_matter::secure_channel::spake2p::VerifierData;
31//!
32//! # use rs_matter::data_model::sdm::dev_att::{DataType, DevAttDataFetcher};
33//! # use rs_matter::error::Error;
34//! # pub struct DevAtt{}
35//! # impl DevAttDataFetcher for DevAtt{
36//! # fn get_devatt_data(&self, data_type: DataType, data: &mut [u8]) -> Result<usize, Error> { Ok(0) }
37//! # }
38//! # let dev_att = Box::new(DevAtt{});
39//!
40//! /// The commissioning data for this device
41//! let comm_data = CommissioningData {
42//!     verifier: VerifierData::new_with_pw(123456),
43//!     discriminator: 250,
44//! };
45//!
46//! /// The basic information about this device
47//! let dev_info = BasicInfoConfig {
48//!     vid: 0x8000,
49//!     pid: 0xFFF1,
50//!     hw_ver: 2,
51//!     sw_ver: 1,
52//!     sw_ver_str: "1".to_string(),
53//!     serial_no: "aabbcc".to_string(),
54//!     device_name: "OnOff Light".to_string(),
55//! };
56//!
57//! /// Get the Matter Object
58//! /// The dev_att is an object that implements the DevAttDataFetcher trait.
59//! let mut matter = Matter::new(dev_info, dev_att, comm_data).unwrap();
60//! let dm = matter.get_data_model();
61//! {
62//!     let mut node = dm.node.write().unwrap();
63//!     /// Add our device-types
64//!     let endpoint = device_type_add_on_off_light(&mut node).unwrap();
65//! }
66//! // Start the Matter Daemon
67//! // matter.start_daemon().unwrap();
68//!
69//! Start off exploring by going to the [Matter] object.
70#![cfg_attr(not(feature = "std"), no_std)]
71#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))]
72#![cfg_attr(feature = "nightly", feature(impl_trait_projections))]
73#![cfg_attr(feature = "nightly", allow(incomplete_features))]
74
75pub mod acl;
76pub mod cert;
77pub mod codec;
78pub mod core;
79pub mod crypto;
80pub mod data_model;
81pub mod error;
82pub mod fabric;
83pub mod group_keys;
84pub mod interaction_model;
85pub mod mdns;
86pub mod pairing;
87pub mod persist;
88pub mod secure_channel;
89pub mod tlv;
90pub mod transport;
91pub mod utils;
92
93pub use crate::core::*;
94
95#[cfg(feature = "alloc")]
96extern crate alloc;
97
98#[cfg(feature = "alloc")]
99#[macro_export]
100macro_rules! alloc {
101    ($val:expr) => {
102        alloc::boxed::Box::new($val)
103    };
104}
105
106#[cfg(not(feature = "alloc"))]
107#[macro_export]
108macro_rules! alloc {
109    ($val:expr) => {
110        $val
111    };
112}