Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions openthread-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ force-esp-riscv-toolchain = []

[build-dependencies]
anyhow = "1"
bindgen = "0.71"
env_logger = "0.10"
bindgen = "0.72"
env_logger = "0.11"
log = "0.4"
cmake = "0.1.52"
cc = "1.1"
Expand Down
2 changes: 2 additions & 0 deletions openthread-sys/gen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl OpenThreadBuilder {
/// - `force_esp_riscv_toolchain`: If true, and if the target is a riscv32 target, force the use of the Espressif RISCV GCC toolchain
/// (`riscv32-esp-elf-gcc`) rather than the derived `riscv32-unknown-elf-gcc` toolchain which is the "official" RISC-V one
/// (https://github.com/riscv-collab/riscv-gnu-toolchain)
#[expect(clippy::too_many_arguments)]
pub fn new(
force_clang: bool,
crate_root_path: PathBuf,
Expand Down Expand Up @@ -95,6 +96,7 @@ impl OpenThreadBuilder {
.derive_debug(false)
.derive_default(true)
.layout_tests(false)
.prepend_enum_name(false)
.allowlist_item("ot.*")
.allowlist_item("OT_.*")
.header(
Expand Down
7 changes: 7 additions & 0 deletions openthread-sys/gen/sysroot/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ extern "C" {

#include <stdint.h>

#if defined(__has_include) && __has_include(<sys/_types/_off_t.h>)
// HACK: MbedTLS ends up including <sys/socket.h> whenever it's available.
// That header ends up pulling in _off_t.h, which conflicts with our own
// definition. Let's just use the system one if we can.
#include <sys/_types/_off_t.h>
#else
// Newlib defines `off_t` as `__SLONGWORD_TYPE`.
typedef long int off_t;
#endif

#ifdef __cplusplus
} // extern "C"
Expand Down
393 changes: 198 additions & 195 deletions openthread-sys/src/include/riscv32imac-unknown-none-elf.rs

Large diffs are not rendered by default.

393 changes: 198 additions & 195 deletions openthread-sys/src/include/riscv32imc-unknown-none-elf.rs

Large diffs are not rendered by default.

393 changes: 198 additions & 195 deletions openthread-sys/src/include/thumbv6m-none-eabi.rs

Large diffs are not rendered by default.

393 changes: 198 additions & 195 deletions openthread-sys/src/include/thumbv7em-none-eabi.rs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions openthread-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
//! Note that this list is likely to change over time.

#![no_std]
#![allow(
rustdoc::bare_urls,
rustdoc::broken_intra_doc_links,
rustdoc::invalid_html_tags,
rustdoc::invalid_rust_codeblocks,
reason = "Documentation is generated from the C header files"
)]
#![allow(unknown_lints)]

pub use bindings::*;
Expand Down
16 changes: 8 additions & 8 deletions openthread/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use crate::sys::{
otDatasetParseTlvs, otDatasetSetActive, otDatasetSetActiveTlvs, otDatasetSetPending,
otDatasetSetPendingTlvs, otError_OT_ERROR_INVALID_ARGS, otError_OT_ERROR_NO_BUFS,
otExtendedPanId, otMeshLocalPrefix, otNetworkKey, otOperationalDataset,
otOperationalDatasetTlvs, otPskc, otTimestamp,
otDatasetSetPendingTlvs, otExtendedPanId, otMeshLocalPrefix, otNetworkKey,
otOperationalDataset, otOperationalDatasetTlvs, otPskc, otTimestamp, OT_ERROR_INVALID_ARGS,
OT_ERROR_NO_BUFS,
};
use crate::{ot, OpenThread, OtActiveState, OtError};

Expand Down Expand Up @@ -203,7 +203,7 @@ impl OperationalDataset<'_> {
raw_dataset: &mut otOperationalDataset,
) -> Result<(), OtError> {
if tlv.len() > ot_tlv.mTlvs.len() {
Err(OtError::new(otError_OT_ERROR_NO_BUFS))?;
Err(OtError::new(OT_ERROR_NO_BUFS))?;
}

ot_tlv.mTlvs[..tlv.len()].copy_from_slice(tlv);
Expand Down Expand Up @@ -366,7 +366,7 @@ impl OpenThread<'_> {
/// Populates the internal OT TLV dataset structure with the given dataset in TLV slice format.
fn fill_dataset_tlv(state: &mut OtActiveState<'_>, dataset: &[u8]) -> Result<(), OtError> {
if state.ot.dataset_resources.dataset_tlv.mTlvs.len() < dataset.len() {
Err(OtError::new(otError_OT_ERROR_NO_BUFS))?;
Err(OtError::new(OT_ERROR_NO_BUFS))?;
}

state.ot.dataset_resources.dataset_tlv.mTlvs[..dataset.len()].copy_from_slice(dataset);
Expand All @@ -390,14 +390,14 @@ impl OpenThread<'_> {
{
let byte = (chf
.to_digit(16)
.ok_or(OtError::new(otError_OT_ERROR_INVALID_ARGS))?
.ok_or(OtError::new(OT_ERROR_INVALID_ARGS))?
<< 4)
| chs
.to_digit(16)
.ok_or(OtError::new(otError_OT_ERROR_INVALID_ARGS))?;
.ok_or(OtError::new(OT_ERROR_INVALID_ARGS))?;

if offset >= state.ot.dataset_resources.dataset_tlv.mTlvs.len() {
Err(OtError::new(otError_OT_ERROR_NO_BUFS))?;
Err(OtError::new(OT_ERROR_NO_BUFS))?;
}

state.ot.dataset_resources.dataset_tlv.mTlvs[offset] = byte as _;
Expand Down
4 changes: 2 additions & 2 deletions openthread/src/enal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::net::{Ipv4Addr, SocketAddr, SocketAddrV6};

use crate::sys::otError_OT_ERROR_FAILED;
use crate::sys::OT_ERROR_FAILED;
use crate::{OpenThread, OtError, UdpSocket};

impl edge_nal::io::Error for OtError {
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<'a> edge_nal::UdpBind for OpenThread<'a> {

fn socket_addr_v6(addr: SocketAddr) -> Result<SocketAddrV6, OtError> {
match addr {
SocketAddr::V4(_) => Err(OtError::new(otError_OT_ERROR_FAILED)),
SocketAddr::V4(_) => Err(OtError::new(OT_ERROR_FAILED)),
SocketAddr::V6(v6) => Ok(v6),
}
}
69 changes: 33 additions & 36 deletions openthread/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,17 @@ mod srp;
mod udp;

use sys::{
otChangedFlags, otDeviceRole, otDeviceRole_OT_DEVICE_ROLE_CHILD,
otDeviceRole_OT_DEVICE_ROLE_DETACHED, otDeviceRole_OT_DEVICE_ROLE_DISABLED,
otDeviceRole_OT_DEVICE_ROLE_LEADER, otDeviceRole_OT_DEVICE_ROLE_ROUTER, otError,
otError_OT_ERROR_ABORT, otError_OT_ERROR_CHANNEL_ACCESS_FAILURE, otError_OT_ERROR_DROP,
otError_OT_ERROR_NONE, otError_OT_ERROR_NOT_FOUND, otError_OT_ERROR_NO_ACK,
otError_OT_ERROR_NO_BUFS, otInstance, otInstanceFinalize, otInstanceInitSingle, otIp6Address,
otIp6GetUnicastAddresses, otIp6IsEnabled, otIp6NewMessageFromBuffer, otIp6Send,
otChangedFlags, otDeviceRole, otError, otInstance, otInstanceFinalize, otInstanceInitSingle,
otIp6Address, otIp6GetUnicastAddresses, otIp6IsEnabled, otIp6NewMessageFromBuffer, otIp6Send,
otIp6SetEnabled, otIp6SetReceiveCallback, otLinkModeConfig, otMessage, otMessageFree,
otMessagePriority_OT_MESSAGE_PRIORITY_NORMAL, otMessageRead, otMessageSettings,
otOperationalDataset, otOperationalDatasetTlvs, otPlatAlarmMilliFired, otPlatRadioReceiveDone,
otPlatRadioTxDone, otPlatRadioTxStarted, otRadioCaps, otRadioFrame, otSetStateChangedCallback,
otTaskletsProcess, otThreadGetDeviceRole, otThreadGetExtendedPanId, otThreadSetEnabled,
otThreadSetLinkMode, OT_CHANGED_THREAD_ROLE, OT_RADIO_CAPS_ACK_TIMEOUT,
OT_RADIO_FRAME_MAX_SIZE,
otMessageRead, otMessageSettings, otOperationalDataset, otOperationalDatasetTlvs,
otPlatAlarmMilliFired, otPlatRadioReceiveDone, otPlatRadioTxDone, otPlatRadioTxStarted,
otRadioCaps, otRadioFrame, otSetStateChangedCallback, otTaskletsProcess, otThreadGetDeviceRole,
otThreadGetExtendedPanId, otThreadSetEnabled, otThreadSetLinkMode, OT_CHANGED_THREAD_ROLE,
OT_DEVICE_ROLE_CHILD, OT_DEVICE_ROLE_DETACHED, OT_DEVICE_ROLE_DISABLED, OT_DEVICE_ROLE_LEADER,
OT_DEVICE_ROLE_ROUTER, OT_ERROR_ABORT, OT_ERROR_CHANNEL_ACCESS_FAILURE, OT_ERROR_DROP,
OT_ERROR_NONE, OT_ERROR_NOT_FOUND, OT_ERROR_NO_ACK, OT_ERROR_NO_BUFS,
OT_MESSAGE_PRIORITY_NORMAL, OT_RADIO_CAPS_ACK_TIMEOUT, OT_RADIO_FRAME_MAX_SIZE,
};

/// A newtype wrapper over the native OpenThread error type (`otError`).
Expand Down Expand Up @@ -122,7 +119,7 @@ impl core::error::Error for OtError {}
macro_rules! ot {
($code: expr) => {{
match $code {
$crate::sys::otError_OT_ERROR_NONE => Ok(()),
$crate::sys::OT_ERROR_NONE => Ok(()),
err => Err($crate::OtError::new(err)),
}
}};
Expand All @@ -139,7 +136,7 @@ pub trait IntoOtCode {
impl IntoOtCode for Result<(), OtError> {
fn into_ot_code(self) -> otError {
match self {
Ok(_) => otError_OT_ERROR_NONE,
Ok(_) => OT_ERROR_NONE,
Err(e) => e.into_inner(),
}
}
Expand Down Expand Up @@ -176,7 +173,7 @@ impl<'a> OpenThread<'a> {
{
// `OpenThread` is already instantiated; can't instantiate another instance
// until all `OpenThread` instances are dropped
Err(OtError::new(otError_OT_ERROR_NO_BUFS))?;
Err(OtError::new(OT_ERROR_NO_BUFS))?;
}

// Needed so that we convert from the the actual `'a` lifetime of `rng` to the fake `'static` lifetime in `OtResources`
Expand Down Expand Up @@ -853,7 +850,7 @@ impl<'a> OpenThread<'a> {
state.ot.instance,
&mut state.ot.radio_resources.snd_frame,
core::ptr::null_mut(),
otError_OT_ERROR_ABORT,
OT_ERROR_ABORT,
);
}
}
Expand Down Expand Up @@ -897,7 +894,7 @@ impl<'a> OpenThread<'a> {
state.ot.instance,
&mut state.ot.radio_resources.snd_frame,
ack_frame_ptr,
otError_OT_ERROR_NONE,
OT_ERROR_NONE,
);
}
}
Expand Down Expand Up @@ -968,7 +965,7 @@ impl<'a> OpenThread<'a> {
otPlatRadioReceiveDone(
instance,
&mut radio_resources.rcv_frame,
otError_OT_ERROR_NONE,
OT_ERROR_NONE,
);
}
}
Expand Down Expand Up @@ -1033,11 +1030,11 @@ impl<'a> OpenThread<'a> {
E: RadioError,
{
match err.kind() {
RadioErrorKind::TxFailed => otError_OT_ERROR_CHANNEL_ACCESS_FAILURE,
RadioErrorKind::TxFailed => OT_ERROR_CHANNEL_ACCESS_FAILURE,
RadioErrorKind::TxAckFailed
| RadioErrorKind::RxAckTimeout
| RadioErrorKind::RxAckInvalid => otError_OT_ERROR_NO_ACK,
_ => otError_OT_ERROR_ABORT,
| RadioErrorKind::RxAckInvalid => OT_ERROR_NO_ACK,
_ => OT_ERROR_ABORT,
}
}
}
Expand Down Expand Up @@ -1205,11 +1202,11 @@ impl From<otDeviceRole> for DeviceRole {
#[allow(non_snake_case)]
fn from(value: otDeviceRole) -> Self {
match value {
otDeviceRole_OT_DEVICE_ROLE_DISABLED => Self::Disabled,
otDeviceRole_OT_DEVICE_ROLE_DETACHED => Self::Detached,
otDeviceRole_OT_DEVICE_ROLE_CHILD => Self::Child,
otDeviceRole_OT_DEVICE_ROLE_ROUTER => Self::Router,
otDeviceRole_OT_DEVICE_ROLE_LEADER => Self::Leader,
OT_DEVICE_ROLE_DISABLED => Self::Disabled,
OT_DEVICE_ROLE_DETACHED => Self::Detached,
OT_DEVICE_ROLE_CHILD => Self::Child,
OT_DEVICE_ROLE_ROUTER => Self::Router,
OT_DEVICE_ROLE_LEADER => Self::Leader,
other => Self::Other(other),
}
}
Expand Down Expand Up @@ -1241,7 +1238,7 @@ impl<'a> OtActiveState<'a> {
let udp = self
.udp
.as_mut()
.ok_or(OtError::new(crate::sys::otError_OT_ERROR_FAILED))?;
.ok_or(OtError::new(crate::sys::OT_ERROR_FAILED))?;

Ok(udp)
}
Expand All @@ -1255,7 +1252,7 @@ impl<'a> OtActiveState<'a> {
let srp = self
.srp
.as_mut()
.ok_or(OtError::new(crate::sys::otError_OT_ERROR_FAILED))?;
.ok_or(OtError::new(crate::sys::OT_ERROR_FAILED))?;

Ok(srp)
}
Expand Down Expand Up @@ -1358,14 +1355,14 @@ impl<'a> OtContext<'a> {
packet.len() as _,
&otMessageSettings {
mLinkSecurityEnabled: true,
mPriority: otMessagePriority_OT_MESSAGE_PRIORITY_NORMAL as _,
mPriority: OT_MESSAGE_PRIORITY_NORMAL as _,
},
)
};

if !msg.is_null() {
let res = unsafe { otIp6Send(state.ot.instance, msg) };
if res != otError_OT_ERROR_DROP {
if res != OT_ERROR_DROP {
ot!(res)?;

trace!("Transmitted IPv6 packet: {}", Bytes(packet));
Expand All @@ -1377,7 +1374,7 @@ impl<'a> OtContext<'a> {

Ok(())
} else {
Err(OtError::new(otError_OT_ERROR_NO_BUFS))
Err(OtError::new(OT_ERROR_NO_BUFS))
}
}

Expand Down Expand Up @@ -1758,7 +1755,7 @@ impl<'a> OtContext<'a> {
);

if index < 0 {
Err(OtError::new(otError_OT_ERROR_NOT_FOUND))?;
Err(OtError::new(OT_ERROR_NOT_FOUND))?;
}

let state = self.state();
Expand All @@ -1767,7 +1764,7 @@ impl<'a> OtContext<'a> {

let len = settings
.get(key, index as _, buf)?
.ok_or(OtError::new(otError_OT_ERROR_NOT_FOUND))?;
.ok_or(OtError::new(OT_ERROR_NOT_FOUND))?;

Ok(len)
}
Expand Down Expand Up @@ -1812,15 +1809,15 @@ impl<'a> OtContext<'a> {
);

if index < 0 {
Err(OtError::new(otError_OT_ERROR_NOT_FOUND))?;
Err(OtError::new(OT_ERROR_NOT_FOUND))?;
}

let state = self.state();

let settings = &mut state.ot.settings;

if !settings.remove(key, Some(index as _))? {
Err(OtError::new(otError_OT_ERROR_NOT_FOUND))?;
Err(OtError::new(OT_ERROR_NOT_FOUND))?;
}

Ok(())
Expand Down
22 changes: 11 additions & 11 deletions openthread/src/netdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ use core::{
};

use openthread_sys::{
otBorderRouterConfig, otError_OT_ERROR_NONE, otNetDataGetNextOnMeshPrefix,
otRoutePreference_OT_ROUTE_PREFERENCE_HIGH, otRoutePreference_OT_ROUTE_PREFERENCE_LOW,
otRoutePreference_OT_ROUTE_PREFERENCE_MED, OT_NETWORK_DATA_ITERATOR_INIT,
otBorderRouterConfig, otNetDataGetNextOnMeshPrefix, OT_ERROR_NONE,
OT_NETWORK_DATA_ITERATOR_INIT, OT_ROUTE_PREFERENCE_HIGH, OT_ROUTE_PREFERENCE_LOW,
OT_ROUTE_PREFERENCE_MED,
};

use crate::{OpenThread, OtError};

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum OtRoutePreference {
/// Low route preference
OtRoutePreferenceLow = otRoutePreference_OT_ROUTE_PREFERENCE_LOW as isize,
OtRoutePreferenceLow = OT_ROUTE_PREFERENCE_LOW as isize,
/// Medium route preference
OtRoutePreferenceMed = otRoutePreference_OT_ROUTE_PREFERENCE_MED as isize,
OtRoutePreferenceMed = OT_ROUTE_PREFERENCE_MED as isize,
/// High route preference
OtRoutePreferenceHigh = otRoutePreference_OT_ROUTE_PREFERENCE_HIGH as isize,
OtRoutePreferenceHigh = OT_ROUTE_PREFERENCE_HIGH as isize,
Unkown = 2,
}

#[allow(non_upper_case_globals, clippy::unnecessary_cast)]
impl OtRoutePreference {
fn from_ot_int(input: i32) -> Self {
// These cast are needed as otRoutePreference_OT_ROUTE_PREFERENCE_* are i8 for thumbv*
// These cast are needed as OT_ROUTE_PREFERENCE_* are i8 for thumbv*
// but i32 for riscv32im*
const value_low: i32 = otRoutePreference_OT_ROUTE_PREFERENCE_LOW as i32;
const value_med: i32 = otRoutePreference_OT_ROUTE_PREFERENCE_MED as i32;
const value_high: i32 = otRoutePreference_OT_ROUTE_PREFERENCE_HIGH as i32;
const value_low: i32 = OT_ROUTE_PREFERENCE_LOW as i32;
const value_med: i32 = OT_ROUTE_PREFERENCE_MED as i32;
const value_high: i32 = OT_ROUTE_PREFERENCE_HIGH as i32;
match input {
value_low => OtRoutePreference::OtRoutePreferenceLow,
value_med => OtRoutePreference::OtRoutePreferenceMed,
Expand Down Expand Up @@ -209,7 +209,7 @@ impl OpenThread<'_> {
&mut network_data_iterator,
&mut a_config,
)
} == otError_OT_ERROR_NONE
} == OT_ERROR_NONE
{
f(Some(OtBorderRouterConfig::from_ot(a_config)))?;
}
Expand Down
6 changes: 3 additions & 3 deletions openthread/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ffi::{c_char, CStr};

use portable_atomic::AtomicUsize;

use openthread_sys::otError_OT_ERROR_NONE;
use openthread_sys::OT_ERROR_NONE;

use crate::sys::{otError, otInstance, otLogLevel, otLogRegion, otRadioCaps, otRadioFrame};
use crate::{IntoOtCode, OtActiveState, OtContext};
Expand Down Expand Up @@ -206,7 +206,7 @@ extern "C" fn otPlatSettingsGet(
}) {
Ok(len) => {
*value_length = len as _;
otError_OT_ERROR_NONE
OT_ERROR_NONE
}
Err(e) => e.into_inner(),
}
Expand Down Expand Up @@ -304,7 +304,7 @@ extern "C" fn otPlatLog(
}
}

otError_OT_ERROR_NONE
OT_ERROR_NONE
}

// Other C functions which might generally not be supported by MCU ROMs or by - say - `tinyrlibc`
Expand Down
Loading