-
Notifications
You must be signed in to change notification settings - Fork 83
utils: zbus proxy for OpenThread Border Router D-Bus interface #457
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2026 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| //! zbus proxies for OpenThread Border Router (`otbr-agent`). | ||
| //! | ||
| //! OTBR exposes a per-Thread-interface D-Bus service named | ||
| //! `io.openthread.BorderRouter.<ifname>` (typically `io.openthread.BorderRouter.wpan0`) | ||
| //! under the well-known object path `/io/openthread/BorderRouter/<ifname>`. | ||
| //! | ||
| //! The full interface is defined in `openthread/src/posix/platform/dbus/` and | ||
| //! documented at <https://github.com/openthread/ot-br-posix>. We only proxy | ||
| //! the surface needed by the controller today; more methods can be added | ||
| //! incrementally without disturbing this module's existing users. | ||
|
|
||
| pub mod border_router; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2026 Project CHIP Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| //! # D-Bus interface proxy for: `io.openthread.BorderRouter` | ||
| //! | ||
| //! Hand-written from the OpenThread sources at | ||
| //! <https://github.com/openthread/ot-br-posix/blob/main/src/dbus/server/introspect.xml> | ||
| //! and verified against a live `otbr-agent` via: | ||
| //! | ||
| //! ```text | ||
| //! busctl introspect io.openthread.BorderRouter.wpan0 \ | ||
| //! /io/openthread/BorderRouter/wpan0 | ||
| //! ``` | ||
| //! | ||
| //! Only the properties/methods needed today are proxied. The interface | ||
| //! exposes many more (`Scan`, `EnergyScan`, `Attach`, `Detach`, | ||
| //! `JoinerStart`, `FactoryReset`, etc.) — they can be added incrementally. | ||
|
|
||
| use zbus::proxy; | ||
|
|
||
| #[proxy( | ||
| interface = "io.openthread.BorderRouter", | ||
| default_service = "io.openthread.BorderRouter.wpan0", | ||
| default_path = "/io/openthread/BorderRouter/wpan0" | ||
| )] | ||
| pub trait BorderRouter { | ||
| /// Active Thread Operational Dataset, TLV-encoded. | ||
| /// | ||
| /// This is the same byte sequence `ot-ctl dataset active -x` emits | ||
| /// (just unhexed). Roughly 100–110 bytes for a typical dataset. | ||
| /// | ||
| /// Returned when there's an active dataset; empty if the device is | ||
| /// disabled/detached. | ||
| #[zbus(property)] | ||
| fn active_dataset_tlvs(&self) -> zbus::Result<Vec<u8>>; | ||
|
|
||
| /// Set the active dataset (TLV-encoded). Triggers re-attach. | ||
| #[zbus(property)] | ||
| fn set_active_dataset_tlvs(&self, value: Vec<u8>) -> zbus::Result<()>; | ||
|
|
||
| /// Pending Thread Operational Dataset, TLV-encoded. | ||
| /// | ||
| /// Used for coordinated dataset rotations. Empty if no pending change. | ||
| #[zbus(property)] | ||
| fn pending_dataset_tlvs(&self) -> zbus::Result<Vec<u8>>; | ||
|
|
||
| /// Device role on the Thread network. One of: | ||
| /// `"disabled" | "detached" | "child" | "router" | "leader"`. | ||
| #[zbus(property)] | ||
| fn device_role(&self) -> zbus::Result<String>; | ||
|
Comment on lines
+57
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The You could define an enum like this, for example, above the use serde::{Deserialize, Serialize};
use zbus::zvariant;
#[derive(Debug, Clone, PartialEq, Eq, zvariant::Type, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[zvariant(signature = "s")]
pub enum DeviceRole {
Disabled,
Detached,
Child,
Router,
Leader,
}Then, you can change the property in the trait to use this enum: #[zbus(property)]
fn device_role(&self) -> zbus::Result<DeviceRole>;This change will prevent bugs related to typos in role strings and make the code that uses this proxy cleaner. |
||
|
|
||
| /// 64-bit IEEE EUI-64 of the Thread radio, as a hex string. | ||
| #[zbus(property)] | ||
| fn eui64(&self) -> zbus::Result<String>; | ||
|
|
||
| /// Currently-active Thread channel (11-26 for 2.4 GHz). | ||
| #[zbus(property)] | ||
| fn channel(&self) -> zbus::Result<u16>; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
#[proxy]macro uses theinterfacename as the default D-Bus service name ifdefault_serviceis not specified. In this case, it would default toio.openthread.BorderRouter.However, the OpenThread D-Bus service is named
io.openthread.BorderRouter.<ifname>, which for the hardcodedwpan0interface would beio.openthread.BorderRouter.wpan0. Without specifying the correctdefault_service, attempts to use this proxy with default settings will fail to connect.Please add the
default_serviceto the#[proxy]attribute.