diff --git a/Cargo.lock b/Cargo.lock index 4880747..237eb62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,8 +6,8 @@ version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "zigbee-rs" -version = "0.1.0" +name = "zigbee" +version = "0.1.0-alpha.1" dependencies = [ "bitmaps 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 03821a7..b6feced 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,19 @@ [package] -name = "zigbee-rs" -version = "0.1.0" +name = "zigbee" +version = "0.1.0-alpha.1" authors = ["Stürmer, Benjamin "] edition = "2018" rust-version = "1.31" -description = "ZigBee protocol stack based on the [ZigBee specification 22 1.0](https://csa-iot.org/wp-content/uploads/2022/01/docs-05-3474-22-0csg-zigbee-specification-1.pdf)" -documentation = "https://docs.rs/zigbee-rs" -homepage = "https://github.com/thebino/zigbee-rs" +description = "ZigBee protocol stack in `no-std` based on the [ZigBee specification 22 1.0](https://csa-iot.org/wp-content/uploads/2022/01/docs-05-3474-22-0csg-zigbee-specification-1.pdf)" +documentation = "https://docs.rs/zigbee" repository = "https://github.com/thebino/zigbee-rs" readme = "README.md" keywords = ["zigbee", "208.15.4"] categories = ["network-programming", "no-std", "embedded"] license = "MIT OR Apache-2.0" +[features] [dependencies] bitmaps = { version = "3.2.1", default-features = false } diff --git a/README.md b/README.md index 64cd22d..617fc7d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# zigbee-rs +# zigbee -[![License](https://img.shields.io/github/license/thebino/zigbee-rs?style=for-the-badge)](./LICENSE-APACHE) -[![GitHub contributors](https://img.shields.io/github/contributors/thebino/zigbee-rs?color=success&style=for-the-badge)](https://github.com/thebino/zigbee-rs/graphs/contributors) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thebino/zigbee-rs/ci.yaml?style=for-the-badge) +[![GitHub contributors](https://img.shields.io/github/contributors/thebino/zigbee-rs?color=success&style=for-the-badge)](https://github.com/thebino/zigbee-rs/graphs/contributors) +[![License](https://img.shields.io/github/license/thebino/zigbee-rs?style=for-the-badge)](./LICENSE.md) ![ZigBee](https://img.shields.io/badge/zigbee-22.1.0-blue?color=4285F4&logo=zigbee&style=for-the-badge) ![Rust](https://img.shields.io/badge/rust-2021-orange?color=E45928&logo=rust&style=for-the-badge) -The ZigBee protocol stack to integrate ZigBee communication into an application. +The ZigBee protocol stack** in `no_std` to integrate ZigBee communication into an application. Zigbee is a wireless communication technology designed for low-power devices in smart homes and industrial settings. It enables these devices to connect and communicate with each other, allowing for efficient control and automation of various systems. diff --git a/src/aps/apsde.rs b/src/aps/apsde.rs index 573458a..fe3e9ab 100644 --- a/src/aps/apsde.rs +++ b/src/aps/apsde.rs @@ -1,9 +1,20 @@ #![allow(dead_code)] use crate::aps::types; +// 2.2.4.1 +// Application support sub-layer data entity – service access point +// +// Interface between the NWK (Network) layer and the APL (Application) layer +// through a general set of services for use by both the ZDO (device object) and the application. +pub(crate) trait ApsdeSap { + fn data_request(request: ApsdeSapRequest) -> ApsdeSapConfirm; +} + + + type DstAddrMode = u8; // 2.2.4.1.1 -struct ApsdeSapRequest { +pub(crate) struct ApsdeSapRequest { dst_addr_mode: DstAddrMode, dst_address: u8, dst_endpoint: u8, @@ -28,7 +39,7 @@ enum ApsdeSapConfirmStatus { AsduTooLong } // 2.2.4.1.2 -struct ApsdeSapConfirm { +pub(crate) struct ApsdeSapConfirm { dst_addr_mode: DstAddrMode, dst_address: u8, dst_endpoint: u8, diff --git a/src/aps/apsme/basemgt.rs b/src/aps/apsme/basemgt.rs index cf72d67..ca029a6 100644 --- a/src/aps/apsme/basemgt.rs +++ b/src/aps/apsme/basemgt.rs @@ -6,7 +6,7 @@ use crate::aps::types; type DstAddrMode = u8; // 2.2.4.3.1 APSME-BIND.request -struct ApsmeBindRequest { +pub(crate) struct ApsmeBindRequest { src_address: u64, src_endpoint: types::SrcEndpoint, cluster_id: u16, @@ -23,7 +23,7 @@ enum ApsmeBindRequestStatus { } // 2.2.4.3.2 APSME-BIND.confirm -struct ApsmeBindConfirm { +pub(crate) struct ApsmeBindConfirm { status: ApsmeBindRequestStatus, src_address: u64, src_endpoint: types::SrcEndpoint, @@ -59,7 +59,7 @@ struct ApsmeUnbindConfirm { dst_endpoint: u8, } -enum AIBAttribute { +pub(crate) enum AIBAttribute { IapsBindingTable = 0xc1, ApsDesignatedCoordinator = 0xc2, ApsChannelMaskList = 0xc3, @@ -80,7 +80,7 @@ struct ApsmeGetRequest { attribute: AIBAttribute } -struct AIBAttributeValue { +pub(crate) struct AIBAttributeValue { } diff --git a/src/aps/apsme/mod.rs b/src/aps/apsme/mod.rs index bba7b3d..799058e 100644 --- a/src/aps/apsme/mod.rs +++ b/src/aps/apsme/mod.rs @@ -1,4 +1,31 @@ +use basemgt::{AIBAttribute, AIBAttributeValue, ApsmeBindConfirm, ApsmeBindRequest}; + pub(crate) mod basemgt; pub(crate) mod groupmgt; +// 2.2.4.2 +// Application support sub-layer management service = service access point +// +// supports the transport of management commands between the NHLE and the APSME +pub(crate) trait ApsmeSap { + // 2.2.4.3.1 + // request to bind two devices together, or to bind a device to a group + fn bind_request(request: ApsmeBindRequest) -> ApsmeBindConfirm; + // 2.2.4.3.3 + // request to unbind two devices, or to unbind a device from a group + fn unbind_request(); + // 2.2.4.4.1 + fn get(attribute: AIBAttribute) -> AIBAttributeValue; + // 2.2.4.4.3 + fn set(); + // 2.2.4.5.1 + fn add_group(); + // 2.2.4.5.1 + fn remove_group(); + // 2.2.4.5.5 + fn remove_all_groups(); +} +// TODO: add AIB (APS information base) a database of managed objects +// +// 2.2.4.4.1 diff --git a/src/aps/types/mod.rs b/src/aps/types/mod.rs index 9600ade..a58ed61 100644 --- a/src/aps/types/mod.rs +++ b/src/aps/types/mod.rs @@ -1,5 +1,3 @@ -//! Bounded address -//! 2.2.4.1.1 use super::error::ApsError; pub struct SrcEndpoint { diff --git a/src/lib.rs b/src/lib.rs index e63ed43..79b373d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,9 @@ -#![no_std] - -//! # zigbee +//! Implements the ZigBee protocol stack in `no-std` based on the [ZigBee specification] //! -//! ZigBee is a protocol stack based on the ZigBee specification 22 1.0 +//! [ZigBee specification]: https://csa-iot.org/wp-content/uploads/2022/01/docs-05-3474-22-0csg-zigbee-specification-1.pdf //! -mod aps; - -mod lib { +#![no_std] -} +mod aps; +pub mod zdo; diff --git a/src/zdo/mod.rs b/src/zdo/mod.rs new file mode 100644 index 0000000..9c78f6f --- /dev/null +++ b/src/zdo/mod.rs @@ -0,0 +1,17 @@ +#![allow(dead_code)] + +#[derive(Debug)] +pub struct ZigbeeDevice { + field: bool +} + +impl ZigbeeDevice { + pub fn new(gpio: u8) -> Self { + Self { field: true } + } + + pub fn discover() { + + } +} +